problem getting json data inside my JqGrid
I am having problem rendering data in my Jqgrid..My JSON data is in this form
[
{
"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"
}
]
and my jqGrid is like this
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"
});
What I am doing wrong in here...any idea
Your JSON is wrong. You've included the data only, not any of the other info the grid requires (record count, page count, etc.). You must use one of these formats.
You should use jsonReader as function (see jquery with ASP.NET MVC - calling ajax enabled web service and http://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; }
}
Another problem is that the data from the latestTime
are not corresponds to data needed for the formatter:"date"
. To fix the problem you can try to use srcformat
and newformat
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:predefined_formatter#predefined_format_types, but I am not sure if it is possible. It seems to me that only numeric date formats are supported.
In the example http://www.ok-soft-gmbh.com/jqGrid/ReadJsonData3.htm I just commented the date format of latestTime
. How can see the problem with reading of data can be solved with respect of jsonReader
which I suggested.
精彩评论