简体   繁体   English

用addRowData添加一行后的jqGrid分页器问题

[英]jqGrid pager problem after adding a row with addRowData

var index = 'id';
var ajaxResponse = [{id: 1, name: 'John', email: 'john@doe.co.uk'}, {id: 2, name: 'Michael', email: 'michael@example.com'}];
$('#grid').addRowData(index, ajaxResponse);

After adding multiple rows one by one the pager doesn't stick to the per page limitation, also the pager reports page 1 of 0. 一页一页地添加多行后,寻呼机将不遵守每页限制,寻呼机也会报告第1页(共0页)。

After i hit the refresh button from the footer of the grid, i see the correct number of rows per page, and the correct number of pages. 从网格的页脚单击刷新按钮后,我会看到每页正确的行数和正确的页数。

Any ideas on how to fix? 有关如何解决的任何想法?

Thanks. 谢谢。

在添加行jQuery("#grid").trigger("reloadGrid");之后调用刷新

You don't posted the full code which you use. 您没有发布使用的完整代码。 So I can only guess what you do. 所以我只能猜你在做什么。

If you have in ajaxResponse the full data which you use to fill the grid you can create the grid with data. 如果您在ajaxResponse具有用于填充网格的全部数据,则可以使用数据创建网格。 You can use data: ajaxResponse together with gridview: true . 您可以将data: ajaxResponsegridview: true一起使用。 In the case the whole grid will be created at once: 在这种情况下,将立即创建整个网格:

var mydata = [
        {id: 1, name: 'John', email: 'john@doe.co.uk'},
        {id: 2, name: 'Michael', email: 'michael@example.com'}
    ];

$("#list").jqGrid({
    datatype: 'local',
    data: mydata,
    colNames: ['Name', 'E-Mail'],
    colModel: [
        {name: 'name', width: 100},
        {name: 'email', width: 150}
    ],
    rowNum: 5,
    rowList: [5, 10, 20],
    pager: '#pager',
    gridview: true,
    rownumbers: true,
    sortname: 'name',
    sortorder: 'desc',
    caption: 'Just simple local grid',
    height: 'auto'
});

(see the demo here ) (请参见此处的演示)

If you get the data from the server in JSON format like this 如果您从服务器以JSON格式获取数据,如下所示

[
    {"id": 1, "name": "John",    "email": "john@doe.co.uk"},
    {"id": 2, "name": "Michael", "email": "michael@example.com"}
]

you can set url parameter to the server URL which provide the data and use 您可以将url参数设置为提供数据并使用的服务器URL

$("#list").jqGrid({
    url: 'Nicolae2.json',
    datatype: 'json',
    jsonReader: {
        repeatitems: false,
        root: function (obj) { return obj; },
        page: function () { return 1; },
        total: function () { return 1; },
        records: function (obj) { return obj.length; }
    },
    loadonce: true,
    colNames: ['Name', 'E-Mail'],
    colModel: [
        {name: 'name', width: 100},
        {name: 'email', width: 150}
    ],
    rowNum: 5,
    rowList: [5, 10, 20],
    pager: '#pager',
    gridview: true,
    rownumbers: true,
    sortname: 'name',
    sortorder: 'asc',
    caption: 'Just simple local grid',
    height: 'auto'
});

to fill the grid per Ajax directly from the server. 直接从服务器填充每个Ajax的网格。 The only restriction that you have to provide correct sorted data. 您必须提供正确的排序数据的唯一限制。 So I changed the sortorder: 'desc' from the previous example to sortorder: 'asc' . 因此,我将上一个示例的sortorder: 'desc'更改为sortorder: 'asc' See the second demo here . 这里查看第二个演示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM