jsonReader : { root: "rows", page: "page", total: "total", records: "records", repeatitems: true, cell: "cell", id: "id", userdata: "userdata", subgrid: {root:"rows", repeatitems: true, cell:"cell" } },
这是标准的jsonReader的写法,它对应的JSondata为
{ "total": "xxx", "page": "yyy", "records": "zzz", "invdata" : [ {"id" :"1", "cell" :["cell11", "cell12", "cell13"]}, {"id" :"2", "cell":["cell21", "cell22", "cell23"]}, ... ] }
我们可以将cell:"" 和id:"0"。 此时的json数据为
{ "totalpages" : "xxx", "currpage" : "yyy", "totalrecords" : "zzz", "invdata" : [ ["1", "cell11", "cell12", "cell13"], ["2", "cell21", "cell22", "cell23"], ... ] }
如果将repeartimes设为false,它会根据返回的json数据字段名字进行搜索。
{
"totalpages" : "xxx",
"currpage" : "yyy",
"totalrecords" : "zzz",
"invdata" : [
{"invid" :"1", "invdate" : "cell11", "note" :"somenote"},
{"invid" :"2", "amount" : "cell22", "tax" :"cell23", "total" :"2345"},
...
]
}
就像上面那样,我们可以不关心数据的顺序,因为会按名字搜索。而这个名字是colModel中的名字。
UserData
如果我们想获取额外的json数据,而不是框架固定的参数,我们可以这么写
jsonReader: {
...
userdata: "userdata",
...
}
对应的json数据是
{
total: "xxx",
page: "yyy",
records: "zzz",
userdata: {totalinvoice:240.00, tax:40.00},
rows : [
{id:"1", cell:["cell11", "cell12", "cell13"]},
{id:"2", cell:["cell21", "cell22", "cell23"]},
... ]
}
获取userdata的方法:jQuery("grid_id").jqGrid('getGridParam', 'userData')。