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
    } // ...
    ]
}

pageTotalpageId而且records似乎没有被使用。从 chrome 控制台和 firebug 中,我找不到有关发送到服务器的分页的参数。

这里有什么问题?

4

1 回答 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 fetched json but has empty rows and no data

于 2012-08-13T07:29:36.000 回答