在我的JqGrid中获取json数据的问题

时间:2010-08-23 17:50:53

标签: json jqgrid

我在Jqgrid中渲染数据时出现问题。我的JSON数据是以这种形式

[
    {
        "orderNumber": "5917500220100811",
        "chainNumber": "1",
        "divisionNumber": "1",
        "customerNumber": "37029",
        "loadNumber": "59175",
        "orderType": "1",
        "stopSeq": 2,
        "latestTime": "Aug 13, 2010 1:12:21 PM",
        "orderStatus": "6",
        "batchNumber": "1059",
        "maxPalletCube": "1982179262",
        "billingFlag": "N",
        "orderDetailsList": [],
        "id": 2384,
        "createdDate": "Aug 11, 2010 6:54:48 PM",
        "createdUser": "USER",
        "lastModifiedDate": "Aug 13, 2010 10:12:21 AM",
        "lastModifiedUser": "USER"
    },
    {
        "orderNumber": "5917500120100811",
        "chainNumber": "1",
        "divisionNumber": "1",
        "customerNumber": "37003",
        "loadNumber": "59175",
        "orderType": "1",
        "stopSeq": 1,
        "latestTime": "Aug 13, 2010 1:12:21 PM",
        "orderStatus": "6",
        "batchNumber": "1056",
        "maxPalletCube": "1982179262",
        "billingFlag": "N",
        "orderDetailsList": [],
        "id": 2385,
        "createdDate": "Aug 11, 2010 6:54:48 PM",
        "createdUser": "USER",
        "lastModifiedDate": "Aug 13, 2010 10:12:21 AM",
        "lastModifiedUser": "USER"
    }
]

我的jqGrid就像这样

jQuery("#list10").jqGrid({
    url: '/cpsb/json/test.json',
    datatype:'json',
    colNames:['Order','Load', 'Gate Time', 'Stop','Customer','Status'], 
    colModel:[  
        {name:'orderNumber',index:'orderNumber', width:55, sorttype:"int"},
        {name:'loadNumber',index:'loadNumber', width:100, sorttype:"int"},
        {name:'latestTime',index:'latestTime', width:80, align:"right",
         sorttype:"date", formatter:"date"}, 
        {name:'stopSeq',index:'stopSeq', width:80, align:"right", sorttype:"int"},
        {name:'customerNumber',index:'customerNumber', width:130,align:"right",
         sorttype:"int"},
        {name:'orderStatus',index:'orderStatus', width:150, sortable:true} ],
    rowNum:10,
    rowList:[10,20,30],
    pager: '#pager10',
    sortname: 'Gate Time',
    sortorder: "desc",
    viewrecords: true,
    multiselect: true,
    caption: "Order Header"
});

我在这里做错了什么......任何想法

2 个答案:

答案 0 :(得分:1)

你的JSON错了。您只包含数据,而不包括网格所需的任何其他信息(记录计数,页数等)。您必须使用one of these formats

答案 1 :(得分:0)

您应该使用jsonReader作为函数(请参阅jquery with ASP.NET MVC - calling ajax enabled web servicehttp://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#jsonreader_as_function)。

jsonReader : {repeatitems: false,
    root: function(obj) {
        return obj;
    },
    page: function (obj) { return 1; },
    total: function (obj) { return 1; },
    records: function (obj) { return obj.length; }
}

另一个问题是来自latestTime的数据与formatter:"date"所需的数据不对应。要解决此问题,您可以尝试使用srcformatnewformat http://www.trirand.com/jqgridwiki/doku.php?id=wiki:predefined_formatter#predefined_format_types,但我不确定是否可行。在我看来,只支持数字日期格式。

在示例http://www.ok-soft-gmbh.com/jqGrid/ReadJsonData3.htm中,我刚评论了latestTime的日期格式。如何看待数据读取问题可以通过我建议的jsonReader来解决。