Jqgrid使用本地数据时如何设置页数

How to set number of pages in Jqgrid when using local data

从客户端传递数据时是否可以覆盖 jqgrid 的行为?我知道这是从服务器获取数据的时候,但我的问题是不同的。 这是 jsfiddle link: http://jsfiddle.net/fott25/wdvsjwrg/

我也会post我的代码,我的html:

<table id="list"></table>
<div id="pager"></div>

这是我的 javascript,其中包含数据和 jqgrid 初始化:

var myData = [{
    id: 1,
    name: "aaz"
}, {
    id: 2,
    name: "bbz"
}, {
    id: 3,
    name: "ccz"
}, ];

$("#list").jqGrid({
    datastr: myData,
    datatype: "jsonstring",
    jsonReader: {
        page: function(datastr) {
            return 2;
        },
        total: function(datastr) { 
            return 10; 
        },
    }, 
    colNames: ["Id", "Name"],
    colModel: [{
        name: "id",
        index: "id",
        sorttype: "int"
    }, {
        name: "name",
        index: "name"
    }],
    rowNum:1,
    caption: "Viz Test",
    pager: '#pager',
});

这是代码的结果:

如您所见,我尝试在 jsonReader 属性中将总页数设置为 10,但 jqgrid 忽略了该属性。将页面设置为第二个工作正常。 是否可以覆盖总页码?

编辑 #1:我尝试将 lastpage 设置为 10,但它不起作用

一般来说updatepager的用法很简单。您只需要设置 jqGrid 的 page recordslastpage 选项,然后将 updatepager 调用为

this.updatepager(false, true);

如果代码在另一个 jqGrid 回调内部执行或

$("#grid")[0].updatepager(false, true);

值得一提的是 updatepager 不要重新加载网格。它只是在寻呼机和 enables/disables 寻呼机按钮中设置值。

将寻呼值的手动设置与 onPaging 回调的实现结合起来非常重要。有关 updatepager.

用法的示例,请参阅 the old answer

请谨慎使用 onPaging 回调,这些选项在不同版本的 jqGrid 中多次更改。您可以在 the wiki article 中阅读有关问题的更多信息。