javascript JqG​​rid 寻呼机问题 - 总页数和记录显示不正确

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3355964/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 00:56:35  来源:igfitidea点击:

JqGrid pager problem - Total pages and records does not display correctly

javascriptjqueryjqgrid

提问by Carlos Lescay

Issue: My jqGrid pager shows Page 1 of NaN instead of the correct number of pages.

问题:我的 jqGrid 寻呼机显示 NaN 的第 1 页而不是正确的页数。

Fiddler shows that I am getting the correct json from my WCF call:

Fiddler 显示我从 WCF 调用中获得了正确的 json:

{"total":1,"page":1,"records":2,"rows":[{JDEVendorNumber":99999999,
 "VendorName":"Super   Vendor","BillID":"99999999wwerer                      ",
 "CommunityName":"Post Abbey                              ",
 "PrimaryAcctNumber":"wwerer","CommunityID":"600402","RecordID":8}]}

My grid setup is as follows:

我的网格设置如下:

$invoiceGrid.jqGrid({
        datatype: 'json',
        mtype: 'GET',
        url: url,
        colNames: ['Vendor Name', 'CommunityName', 'Primary Acct Nbr', 'BillID'],
        colModel: [
                        { name: 'VendorName', index: 'VendorName', width: 203, align: 'left' },
                        { name: 'CommunityName', index: 'CommunityName', width: 215, align: 'left' },
                        { name: 'PrimaryAcctNumber', index: 'PrimaryAcctNumber', width: 260, align: 'left' },
                        { name: 'BillID', index: 'BillID', hidden: true }
                     ],
        rowNum: 50,
        gridview: true,
        rowList: [10, 20, 30, 50],
        pager: $('#invoicepager'),
        sortname: 'PrimaryAcctNumber',
        viewrecords: true,
        sortorder: "asc",
        rownumbers: false,
        hidegrid: false,
        repeatitems: false,
        recordtext: 'Bill(s) {0} - {1} ',
        cell: "",
        height: "auto",
        loadComplete: function(data) {
           //alert('total is ' + data.responseText);
            if ($invoiceGrid.jqGrid('getGridParam', 'records') == 0) {
                NoRecordsFound();
            } else {
                SetSearchResultsInterface('bills');
            }

            EnableControl($search, true);
            Global.grdInitialized = true;
            $progressbar.hide();
        },
        jsonReader: {

            repeatitems: false,
            id: "RecordID"
        }
    }).navGrid('#invoicepager', { edit: false, add: false, del: false, search: false, refresh: false });

My data is displayed correctly but the pager shows NaN for total pages and total records. Any ideas? Thank you for your help

我的数据显示正确,但寻呼机显示总页数和总记录数为 NaN。有任何想法吗?谢谢您的帮助

回答by Oleg

It seems that correct format of recordtextshould has 3 elements like

似乎正确的格式recordtext应该有 3 个元素,例如

recordtext: "View {0} - {1} of {2}"

You use

你用

recordtext: 'Bill(s) {0} - {1} '

You can use

您可以使用

recordtext: 'Bill(s) {0} - {1} of {2}'

instead. But I can not really reproduce your problem also in case of the usage of your original data (see http://www.ok-soft-gmbh.com/jqGrid/PagerProblem.htmwhich has no problems). Moreover your JSON data should be fixed:

反而。但是,在使用原始数据的情况下,我也无法真正重现您的问题(请参阅http://www.ok-soft-gmbh.com/jqGrid/PagerProblem.htm没有问题)。此外,您的 JSON 数据应该是固定的:

[{JDEVendorNumber"

should be fixed to

应该固定到

[{"JDEVendorNumber"

but probably it's come during posting the data only.

但可能只是在发布数据期间出现的。

回答by Carlos Lescay

Oleg, by looking at the sample code you sent me, I figured that for the pager to work correctly you need to include grid.formedit.js. In my page I had references only to grid.locale-en.js and jquery.jqGrid.min.js. Apparently that is not enough. I guess, lesson learned for me is to include all the .js libraries that are part of the jqGrid download. Thanks for your help

Oleg,通过查看您发送给我的示例代码,我认为要使寻呼机正常工作,您需要包含 grid.formedit.js。在我的页面中,我只引用了 grid.locale-en.js 和 jquery.jqGrid.min.js。显然这还不够。我想,我学到的教训是包含所有 .js 库,这些库是 jqGrid 下载的一部分。谢谢你的帮助

回答by philippe_b

Although it does not seem to be the problem here, the loadonceparameter may cause a similar issue (total pages always set to 1). It should be forced to false:

虽然看起来不是这里的问题,但该loadonce参数可能会导致类似的问题(总页数始终设置为 1)。它应该被迫false

$myGrid.jqGrid({
        datatype: 'json',
        loadonce: false,
        ...
}

The loadonceparameter prevents the client from loading further data after the initial load. As a side effect, the client ignores totaland recordsin the server's response, using only the amount of rows to populate the pager.

loadonce参数防止客户端在初始加载后加载更多数据。作为副作用,客户端在服务器的响应中忽略totalrecords仅使用行数来填充寻呼机。

In my own code, loadoncemust have been defaulted to true, because the pager worked as soon as I explicitly set it to false.

在我自己的代码中,loadonce必须默认为true,因为只要我明确地将它设置为,寻呼机就会工作false