如何在asp.net mvc中的客户端Kendo UI网格中实现服务器端分页

Pan*_*kaj 27 asp.net-mvc kendo-ui

任何人都可以告诉我如何使用客户端Kendo UI Grid实现服务器端分页?

Ata*_*hev 60

更新:我们已经发布了一个开源.NET库,它使分页,过滤分类变得更加容易.

该网格将发送当前pageSizeskip一旦你设置serverPagingtrue.在服务器端,您应使用提供的信息对数据进行分页,并将其与项目总数一起返回.这是一段代码:

行动

public ActionResult Products(int pageSize, int skip) 
{
     using (var northwind = new NorthwindDataContext())
     {
        var products = northwind.Products;
        // Get the total number of records - needed for paging
        var total = products.Count();

        // Page the data
        var data = products.Skip(skip).Take(pageSize).ToList();

        // Return as JSON - the Kendo Grid will use the response
        return Json(new { total = total, data = data });
     }
}
Run Code Online (Sandbox Code Playgroud)

视图

$("#grid").kendoGrid({
    dataSource: {
        transport: {
            read: {
               url: "home/products",
               dataType: "json",
               type: "POST"
            }
        },
        schema: {
            data: "data", // records are returned in the "data" field of the response
            total: "total" // total number of records is in the "total" field of the response
        },
        serverPaging: true // enable server paging
    }
});
Run Code Online (Sandbox Code Playgroud)

参考

使用LINQ进行分页

DataSource配置设置

  • 当使用ToDataSourceResult扩展方法时,MVC包装器会自动执行此操作.以下是文档:http://docs.kendoui.c​​om/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/ajax-binding (5认同)