谁能告诉我如何使用客户端 Kendo UI Grid 实现服务器端分页?
更新:我们有released http://blogs.telerik.com/kendoui/posts/14-01-02/kendo-ui-open-sources-dynamic-linq-helpers一个开源 .NET 库,使分页、排序和过滤变得更加容易。
电网将发送当前pageSize
and skip
一旦你设置serverPaging
to true
。在服务器端,您应该使用提供的信息对数据进行分页,并将其与项目总数一起返回。这是一个代码片段:
Action
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 });
}
}
View
$("#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
}
});
参考
使用 LINQ 进行分页
- Take() 和 Skip() http://beyondrelational.com/modules/1/justlearned/0/tips/9313/take-and-skip-methods-makes-paging-simplified-in-linq.aspx
数据源配置设置
- 服务器分页 http://docs.telerik.com/kendo-ui/api/framework/datasource#configuration-serverPaging
- 模式.数据 http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.data
- 架构.total http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.total
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)