Telerik Extensions for ASP.NET MVC

Version Q2 2012, released 06/07/2012

Custom Server Binding

Drag a column header and drop it here to group by that column
Order ID
Filter
Contact Name
Filter
Ship Address
Filter
Order Date
Filter
10248Paul Henriot59 rue de l'Abbaye07/04/1996
10249Karin JosephsLuisenstr. 4807/05/1996
10250Mario PontesRua do Paço, 6707/08/1996
10251Mary Saveley2, rue du Commerce07/08/1996
10252Pascale CartrainBoulevard Tirou, 25507/09/1996
10253Mario PontesRua do Paço, 6707/10/1996
10254Yang WangHauptstr. 3107/11/1996
10255Michael HolzStarenweg 507/12/1996
10256Paula ParenteRua do Mercado, 1207/15/1996
10257Carlos HernándezCarrera 22 con Ave. Carlos Soublette #8-3507/16/1996
Displaying items 1 - 10 of 830

About this example ASPXRazor

This example shows how to configure Telerik Grid for ASP.NET MVC to use custom server binding. By default the Grid is using the built-in Linq expression engine. However in some cases you may want to perform the paging, sorting, filtering and grouping by yourself. This examples shows how.

The required steps are:

  1. Configure the grid to use custom binding
    <%= Html.Telerik().Grid(Model)
            .Name("Grid")
            .EnableCustomBinding(true)
    %>
    
  2. If using grouping you will need to set BindTo method to the data from which the grid will be populated and explicitly declare the item's type.
    <%= Html.Telerik().Grid<Order>()
            .Name("Grid")
            .BindTo(Model)
            .EnableCustomBinding(true)
    %>
    
  3. If using paging you need to set the Total specifying the total number of records the grid is going to display. This is required for the proper pager configuration.
    <%= Html.Telerik().Grid(Model)
            .Name("Grid")
            .EnableCustomBinding(true)
            .Pageable(paging => paging.Total((int)ViewData["total"]))
    %>
    
  4. The action method which returns data for the grid accepts an argument of type GridCommand. The command object contains all required information to data bind the grid - current page, sorted columns, filter and groups. The action method must be decorated with the GridAction attribute.
    [GridAction]
    public ActionResult _CustomBinding(GridCommand command)
    {
        IEnumerable data = GetData(command);
        var dataContext = new NorthwindDataContext();
        ViewData["total"] = dataContext.Orders.Count();
        return View(data);
    }
    
  5. The GetData method from the previous step performs the actual paging and sorting based on the data in the command argument. Check the controller code for the implementation.

Interested in HTML5 and mobile-powered ASP.NET MVC apps?

Experience the next generation UI and framework for ASP.NET MVC development by downloading trial evaluation copy of Kendo UI Complete for ASP.NET MVC. Jumpstart your development with the available learning resources.

The differences between Telerik MVC Extensions and Kendo UI Complete for ASP.NET MVC, and their licensing models are explained here and here.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Other Demos: