Jam*_*mar 3 asp.net jquery kendo-ui
再次分页不起作用,直到我单击列标题进行排序,然后分页似乎工作正常。
<script type="text/javascript">
$(document).ready(function () {
$('#reportContainer').load('Reports/Scaffold.html', function () {
var dataSource = new kendo.data.DataSource({
transport: {
read: {
type: "POST",
url: Reports.ServiceURL.MyService,
dataType: "JSON",
contentType: "application/json",
data: { myParam: "1" },
serverPaging: true,
serverSorting: true
},
parameterMap: function (data, operation) {
return kendo.stringify(data);
}
},
batch: true,
pageSize: 50,
schema: {
data: "d"
}
});
$("#allGrids").kendoGrid({
dataSource: dataSource,
sortable: true,
pageable: true,
filterable: false,
height: 400,
columns: myModel
});
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
似乎你想选择serverPaging 但你把它放在错误的地方。它是 的字段DataSource而不是 的字段transport.read。您应该将其定义为:
var dataSource = new kendo.data.DataSource({
transport : {
read : {
type : "POST",
url : Reports.ServiceURL.MyService,
dataType : "JSON",
contentType: "application/json",
data : { myParam: "1" }
},
parameterMap: function (data, operation) {
return kendo.stringify(data);
}
},
serverPaging : true,
serverSorting: true,
batch : true,
pageSize : 50,
schema : {
data: "d"
}
});
Run Code Online (Sandbox Code Playgroud)
注意:不要忘记,当您定义时schema.data,您还需要定义记录总数,如果它来自服务器,您可能有以下内容:
schema : {
data: "d",
total: "total"
}
Run Code Online (Sandbox Code Playgroud)
并且服务器应该返回一些类似于以下内容的 JSON:
{
"d": [
...
],
"total": 100
}
Run Code Online (Sandbox Code Playgroud)
哪里100是服务器中的总数或记录数,而不是 中的记录数d。
如果不是, serverPaging你可以简单地做:
schema : {
data: "d",
total: function(data) { return data.d.length; }
}
Run Code Online (Sandbox Code Playgroud)
@BurkeHolland,如果您想知道正在发生的事情是网格实际上没有做,serverPaging并且可能没有接收total或无法计算它。它既不在serverPaging模式中也不在serverSorting模式中,所以当@SkildLobster 点击标题时,它对结果进行排序(可能它们已经排序了)然后它从网格数据长度计算出总记录数,最终能够计算页面.
| 归档时间: |
|
| 查看次数: |
1904 次 |
| 最近记录: |