jqGrid分页不起作用

问题描述 投票:0回答:1

jqGrid 好像只显示第一页,服务器好像是对的。

这里是js:

$("#gpaTable").jqGrid({
    datatype: "local",
    pager: "#gpaPager",
    viewrecords: true, 
    jsonReader: {
        repeatitems: true,
        id: "lineId",
        cell: "cell",
        root: "rows",
        records: "records",
        total: "pageTotal",
        page: "pageId"
    },
    ...
});
$("#gpaTable").jqGrid("navGrid", "#gpaPager", { edit: false, add: false, del: false });

$.ajax({
    type: 'POST',
    url: 'alarmInfo.aspx',
    data: { lowestGpa: '1.7' },
    dataType: "json",
    success: function (data) {
        var rows = data['rows'];
        var cnt = rows.length;
        for (var i = 0; i < cnt; ++i) {
            $("#gpaTable").jqGrid("addRowData", i + 1, rows[i]["cell"]);
        }
    }
});

服务器(使用ASP.NET)返回的内容是:

{
    "pageId": "1",
    "pageTotal": "4",
    "records": "100",
    "rows": [{
        "cell": {
            "expectGpa": "2.0",
            "failRestCnt": 1,
            "failTotalCnt": 3,
            "lastGpa": 0.0,
            "lowScore": "",
            "name": "name0063",
            "noScore": 13,
            "star": " ",
            "studentId": "5090379063"
        },
        "lineId": 1
    } // ...
    ]
}

pageTotal
pageId
records
似乎没有被使用。从 Chrome 控制台和 Firebug 中,我找不到有关发送到服务器的分页的参数。

这里有什么问题?

ajax pagination jqgrid
1个回答
1
投票

事实证明

datatype: "local"
不应该用于ajax获取数据。

正确的做法是:

url: "alarmInfo.aspx?request=BasicGpaInfo&lowestGpa=1.7",
datatype: "json",

注意返回的json应该是:

{
    "total": "1",
    "page": "1",
    "records": "2",
    "rows": [
        {
            "id": "1",
            "cell": ["1", "1", "6", "0", "Credit Card", "Movie Hall Pass",
                     "250.0", "2011-03-16", "Entertainment" ]
        },
        ...
    ]
}

而不是

{
    "total": "1",
    "page": "1",
    "records": "2",
    "rows": [
        {
            "id": "1",
            "cell": {
                "accountId": 1,
                "userId": 1,
                "transactionId": 6,
                "subCatId": 0,
                "accountName": "Credit Card",
                "remarks": "Movie Hall Pass",
                "amount": 250.0,
                "transactionDate": "2011-03-16",
                "subCatName": "Entertainment"
            }
        },
        ...
    ]
}

参考这里:jqGrid 获取 json 但有空行且没有数据

© www.soinside.com 2019 - 2024. All rights reserved.