开发者

jqGrid is empty, even though pager shows results

I'm upgrading from jqGrid 3.6.3 -> 4.1.2.

After upgrading the grid always displays empty, even though the pager shows the correct number of results (6 in this case). I can see that the JSON is being retrieved and is valid.

No error is displayed, and nothing is written to the javascript console. If I hook into the loadComplete event, it fires -- and grid.getDataIDs() returns an empty array - as if there were no data.

Here is the JSON being transmitted (formatted with JSONLint). It is properly formatted JSON & passes JSONLint validation:

{
    "pageCount": "1",
    "pageSize": "15",
    "pageNumber": "1",
    "itemCount": "6",
    "items": [
        {
            "Id": "1",
            "Name": "Administrator"
        },
       开发者_Go百科 {
            "Id": "3",
            "Name": "asfasfassf"
        },
        {
            "Id": "6",
            "Name": "askjdhajksdk sh"
        },
        {
            "Id": "2",
            "Name": "fg"
        },
        {
            "Id": "5",
            "Name": "test"
        },
        {
            "Id": "4",
            "Name": "sa afasf saf"
        }
    ]
}

Here is the relevant portion of the jqGrid options that I am passing into jqGrid:

{
    datatype: 'json',
    jsonReader: {
        root: 'items',
        id: '0',
        repeatitems: false,
        page: 'pageNumber',
        total: 'pageCount',
        records: 'itemCount'
    },
    mtype: 'POST',
    ...
};

I have scoured the interwebs for an answer, but no luck. Does anyone have a suggestion?!

See below a screenshot of the options object that I am passing into jqGrid(options):

jqGrid is empty, even though pager shows results

Thanks in advance!!!


Add cell: '' to your jsonReader:

jsonReader: {
    root: 'items',
    id: '0',
    repeatitems: false,
    page: 'pageNumber',
    total: 'pageCount',
    records: 'itemCount',
    cell: ''
}

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_data

By default, the jsonReader's cell option is set to "cell", which would mean your data would need to be formatted like this:

{
    "pageCount": "1",
    "pageSize": "15",
    "pageNumber": "1",
    "itemCount": "6",
    "items": [
        {
            "Id": "1",
            "cell": ["Administrator"]
        },
        {
            "Id": "3",
            "cell": ["asfasfassf"]
        }
    ]
}

Also, take a look at the upgrade guide for v3.6.4 to v3.6.5: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:upgrade_from_3.6.4_to_3.6.5


I solved the problem & the issue was completely unrelated to JSON.

After upgrading to jqGrid 4.1.2 I found that my grid table needed to have an id attribute. Unfortunately, I had set an invalid ID on the table (it, by accident, had spaces in it).

Once I fixed the table's id attribute, the grid started rendering correctly.

Thanks for your answers!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜