This example shows how to configure Telerik Grid for ASP.NET MVC to use custom 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 and filtering 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 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"]))
    %>
    
  3. 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 and filter. The action method must be decorated with the GridAction attribute and its EnableCustomBinding property must be set to true.
    [GridAction(EnableCustomBinding = true)]
    public ActionResult _CustomBinding(GridCommand command)
    {
        IEnumerable<Order> data = GetData(command);
    
        var dataContext = new NorthwindDataContext();
        return View(new GridModel { Data = data, Total = dataContext.Orders.Count() });
    }
    
  4. 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.