Kendo UI Grid 总是从第 0 页开始
Posted
技术标签:
【中文标题】Kendo UI Grid 总是从第 0 页开始【英文标题】:Kendo UI Grid Always Starts at Page 0 【发布时间】:2012-12-24 14:29:19 【问题描述】:我有一个 Kendo UI Grid,它总是从 0 开始。
如果我更改某一列的排序,那么它会变为 1 并显示其他页码。
我做错了什么?
这是我的代码:
$('#userGrid').kendoGrid(
dataSource:
pageSize: 5,
transport:
read:
url: ROOT+"user/user-list",
,
update:
url: ROOT+"user/update-user",
dataType: "POST"
,
error: function(e)
alert(e.responseText);
,
schema:
data: "data",
model:
id: 'id',
fields:
username: type: "string", editable: false,
type:
type: "number",
editable: true,
validation: required: true
,
level:
type: "number",
editable: true,
validation: required: true
,
firstName: type: "string", editable: true,
middleName: type: "string", editable: true,
lastName: type: "string", editable: true,
DoB: type: "date", editable: true,
dateStarted: type: "date", editable: false,
enabled:
type: "number",
editable: true,
validation: required: true
,
,
toolbar: ["save", "cancel"],
sortable: true,
pageable:
refresh: true,
pageSizes: false
,
editable:true,
columns:
[
field: "username",
width: 90,
title: "Username"
,
field: "type",
width: 50,
title: "Type"
,
field: "level",
width: 25,
title: "Level"
,
field: "firstName",
width: 50,
title: "First name"
,
field: "middleName",
width: 50,
title: "Middle name"
,
field: "lastName",
width: 50,
title: "Last name"
,
field: "DoB",
width: 40,
title: "DoB",
template: '#= kendo.toString(DoB,"dd/MM/yyyy") #'
,
field: "dateStarted",
width: 40,
title: "Started",
template: '#= kendo.toString(dateStarted,"dd/MM/yyyy") #'
,
field: "enabled",
width: 40,
title: "Enabled"
]
)
)
) ;
)
"data":["id":"1","username":"admin@eu","type":"1","level":"12","firstName":"Tom","middleName":"C","lastName":"Higgins","DoB":"0000-00-00","dateStarted":"0000-00-00","enabled":"0","id":"36","username":"liam.spelman@euautomation.com","type":"4","level":"12","firstName":"Liam","middleName":"","lastName":"Spelman","DoB":"0000-00-00","dateStarted":"0000-00-00","enabled":"0","id":"56","username":"adf@sadf.com","type":"4","level":"1","firstName":"asdf","middleName":"","lastName":"asdf","DoB":"1970-01-01","dateStarted":"0000-00-00","enabled":"0","id":"57","username":"adf@saddf.com","type":"4","level":"1","firstName":"asdf","middleName":"","lastName":"asdf","DoB":"1970-01-01","dateStarted":"0000-00-00","enabled":"0"], "rowcount": 4
【问题讨论】:
【参考方案1】:您的服务器是否返回了total
的记录数?
如果是,则将schema
定义为(假设total_size
是服务器返回记录总数的位置):
schema :
data: "data",
total: "total_size",
model:
...
如果没有,请尝试在您的 schema
中添加一个 total
函数,该函数从 data
数组的大小获取它:
schema :
data: "data",
total: function(data)
return data.data.length;
,
model:
...
【讨论】:
谢谢,已经解决了页码问题,但我忘了说,我也有“NaN - NaN of 4 items”,我该如何解决这个问题? (它显示了当你对列进行排序时应该做什么) 嗯!它应该修复两者!如果您单击网格刷新按钮,它会得到修复吗?收到的数据是什么样子的? 我在一个从服务器返回的数据示例中进行了编辑。 Kendo UI 网格文档还有很多不足之处!! 另外你知道我如何实现服务器端分页和排序等吗?或者你知道我可以阅读的一个很好的参考资料,因为我在我想做的这些东西上找不到任何东西:( 我在博客中写了一些关于发送到服务器以实现它的数据以及响应的样子。以上是关于Kendo UI Grid 总是从第 0 页开始的主要内容,如果未能解决你的问题,请参考以下文章