Implement Kendo Grid Using ASP MVC 5.0

We are briefly going to discuss the Kendo Grid and its uses.

  1. Introduction
  2. Kendo Installation
  3. Use Kendo script and style
  4. Kendo Attributes
  5. Kendo Grid

Now, we will discuss each point one by one.

Introduction

Kendo has various operations such as how to perform an action and operations with records. It has paging, filtering, sorting, editing, grouping, fixed pages, and column lockable functionalities.

Kendo Installation

Install the Kendo tool along with your Visual Studio. VS2015 is the best to work with Kendo.

If you have installed Kendo Grid, the .dll file will be placed under the directory: C:\Program Files (x86)\Progress\Telerik UI for ASP.NET MVC R1 2018\wrappers\aspnetmvc\Binaries\Mvc5

Kendo.dll Location

Kendo

It has three different directories --  MVC3, MVC4, and MVC5.

Script files

The script files will be available in the following directory:

C:\Program Files (x86)\Progress\Telerik UI for ASP.NET MVC R1 2018\vsdoc

CSS styles

The style files will be located in C:\Program Files (x86)\Progress\Telerik UI for ASP.NET MVC R1 2018\styles directory.

Use Kendo script and style

The Script and Styles should be added inside the project to generate Kendo Grid and other related functionalities. Find the below screenshots.

Kendo

Including the version as a directory is a better format to understand others.

Kendo Attributes

The below attributes will be used in the Kendo Grid tool.

  1. Filterable
    It will filter your data on the Grid. You can see the equal data, not equal data, starting with letter/word, containing data etc.

    Kendo

  2. Pagination
    The pagination method is used to move from one page to another or directly move on the last/ first page in the grid.

    Kendo

  3. Sortable
    The sortable option is used to order the grid based on column records. We can order it by ascending and descending format.

    We can directly click on the grid to sort the data. Find the below screenshot for reference.

    Kendo

Like this, we have a lot of ways to implement the option for Kendo Grid.

Kendo Grid

Now, we are going to see the simple code to generate Kendo Grid on the application. So, make sure that you have installed all other related files that have been imported into the application directory. 

Find the sample code for reference.

  1. @(Html.Kendo().Grid(Model).Name("Grid").TableHtmlAttributes(new { @class = "table table-striped" })  
  2.             .Columns(columns =>  
  3.             {  
  4.                 columns.Bound(x => x.Name);  
  5.                 columns.Bound(x => x.CreateDate);  
  6.                 columns.Template(@<text>  
  7.                                     @Html.ActionLink("Details""Details"new { id = item.ID })  
  8.                                 </text>)  
  9.                                 .HeaderTemplate("Options")  
  10.                                 .HeaderHtmlAttributes(new { @class = "text-center options-column" })  
  11.                                 .HtmlAttributes(new { @class = "text-center" })  
  12.                                 .ClientTemplate(  
  13.                                     Html.ActionLink("Details""Details"new { id = "REPLACEME" }).ToHtmlString().Replace("REPLACEME""#:ID#")  
  14.                                 );  
  15.             })  
  16.             .Pageable(p => {  
  17.                                 p.Enabled(true);  
  18.                                 p.PageSizes(new int[] { 5, 15, 25, 50, 100, 500 });  
  19.                             })  
  20.             .Sortable()  
  21.   
  22.                                                 .Filterable(filterable => filterable  
  23.                                                 .Extra(true)  
  24.                                                 .Operators(n => n  
  25.                                                     .ForString(str => str.Clear()  
  26.                                                         .Contains("Contains")  
  27.                                                         .StartsWith("Starts with")  
  28.                                                         .EndsWith("Ends with")  
  29.                                                         .IsNotEqualTo("Is not equal to")  
  30.                                                         .DoesNotContain("Does not contain")  
  31.                                                     )))  
  32.             .HtmlAttributes("options-column")  
  33.             .DataSource(dataSource => dataSource.Ajax()  
  34.                     .PageSize(15)  
  35.                     .Destroy(update => update.Action("EditingInline_Destroy""Grid"))  
  36.                     .Read(read => read.Action("Corporations_Read""Corporations")))  
  37.             .Events(events => events.DataBound("GridDataBound"))     
  38.         )  

The above code contains the attributes and formats.

Output

Kendo

Hope this format helps to learn about kendo grid. In the grid, you can see that the action method “Corporations_Read” is called to get the data from the database. Find the below Controller method.

And “Corporations” is a Controller.

Controller

  1. public ActionResult Corporations_Read([DataSourceRequest] DataSourceRequest request)  
  2. {  
  3.    return Json(new PrsData.Models.CorporateHeadquarters().GetCorporateHeadquarters().ToDataSourceResult(request));  
  4. }  

Hope this helps.

Thanks!


Similar Articles