jquery - 用于 jQuery 分页的 Kendo UI 不起作用 - “没有要显示的项目”
问题描述
我使用 Kendo UI 网格并将 json 格式的数据传递给它。“总计”字段为 1157,页面大小为 10。我想控制服务器端分页,但在 Kendo 网格的底部显示“没有要显示的项目”消息。这是我的 index.cshtml:
<div dir="rtl"><div id="grid" class="k-rtl"></div></div>
<script at="Foot">
$(document).ready(function(){
$("#grid").kendoGrid({
columns: [{
field: "Fullname",
title: "name"
}],
dataSource: {
transport: {
type: "json",
read: "/pms/Persons/Persons_Read",
data: {
format: "json"
}
},
schema: {
data: "Data",
total: "Total"},
serverPaging: true,
pageSize: 10
},
pageable: true
});
});
</script>
这是服务器端 Persons 控制器操作:
[AcceptVerbs("Get")]
public ActionResult Persons_Read([DataSourceRequest]DataSourceRequest request)
{
return Json(Getpersons().ToDataSourceResult(request));
}
网格仅显示 10 条第一条记录,之后有 0 页。
解决方案
我做了一个几乎和你一样的测试演示,它在我这边运行良好。我做了以下修改
1.列首字母field
应为小写“fullName”
columns: [{
field: "fullName",
title: "name"
}],
2.数据和总数也要小写
schema: {
data: "data",
total: "total"
},
下面是代码:
模型:
public class Person
{
public string FullName { get; set; }
}
看法:
<div dir="rtl"><div id="grid" class="k-rtl"></div></div>
@section scripts{
<script at="Foot">
$(document).ready(function () {
$("#grid").kendoGrid({
columns: [{
field: "fullName",
title: "name"
}],
dataSource: {
transport: {
type: "json",
read: "/Person/Persons_Read",
data: {
format: "json"
}
},
schema: {
data: "data",
total: "total"
},
serverPaging: true,
pageSize: 10
},
pageable: true,
});
});
</script>
}
控制器:
public class PersonController : Controller
{
[AcceptVerbs("Get")]
public ActionResult Persons_Read([DataSourceRequest] DataSourceRequest request)
{
return Json(Getpersons().ToDataSourceResult(request));
}
private List<Person> Getpersons()
{
var people = new List<Person>();
for (int i = 0; i < 1157; i++)
{
var person = new Person()
{
FullName = "Person"+i
};
people.Add(person);
}
return people;
}
}
结果:
推荐阅读
- python-3.x - Assigning different variable names for every group in df.groupby in python using loops
- nfc - How to enable web app U2F via NFC on mobile
- android - 使用填充和无边距约束布局,忽略一些间距
- python - 尽管使用 for 循环添加元素,为什么我的列表仍为空
- c - 转换为C中的所有大写字母错误
- java - 如何使用 jsoup 检索标签数据
- python-3.x - 通过两个值查找字典
- c# - 如何在服务器上的 ASP.NET Core 产品上禁用“尝试重新连接到服务器”消息
- java - 是否可以通过改造在 listView 中获取 Double 值数组?
- python - 使用范围和列表方法构造列表