Data Types supported by jqgrid: XML, JSON, jsonp, local or clientside, xmlstring, and jsonstring
, Script, function (...).
JSON data
Jsonreader needs to be defined to correspond to the data returned by the server. Its default value is:
· Jsonreader :{
· Root: "rows ",
· Page: "page ",
· Total: "Total ",
· Records: "records ",
· Repeatitems: True,
· Cell: "cell ",
· ID: "ID ",
· Userdata: "userdata ",
· Subgrid: {root: "rows ",
· Repeatitems: True,
· Cell: "cell"
·}
The data format returned by the server is as follows:
·{
· Total: "XXX ",
· Page: "yyy ",
· Records: "Zzz ",
· Rows :[
· {ID: "1", cell: ["cell11", "cell12", "cell13"]},
· {ID: "2", cell: ["cell21", "cell22", "cell23"]},
·...
·]
·}
Jsonreader attributes
Total |
Total number of pages |
Page |
Current page |
Records |
Number of records queried |
Rows |
Array containing actual data |
ID |
Row ID |
Cell |
All cells in the current row |
Custom:
· Jquery ("# gridid"). jqgrid ({
·...
· Jsonreader :{
· Root: "invdata ",
· Page: "currpage ",
· Total: "totalpages ",
· Records: "totalrecords ",
· Cell: "invrow"
·},
·...
·});
· Totalpages: "XXX ",
· Currpage: "yyy ",
· Totalrecords: "Zzz ",
· Invdata :[
· {ID: "1", invrow: ["cell11", "cell12", "cell13"]},
· {ID: "2", invrow: ["cell21", "cell22", "cell23"]},
·...
·]
Repeatitems
It indicates that the data in each row can be repeated. If it is set to false, the elements will be searched by name from the returned data. This name is the name in colmodel.
· Jsonreader :{
· Root: "invdata ",
· Page: "currpage ",
· Total: "totalpages ",
· Records: "totalrecords ",
· Repeatitems: false,
· ID: "0"
·}
· Totalpages: "XXX ",
· Currpage: "yyy ",
· Totalrecords: "Zzz ",
· Invdata :[
· {Invid: "1", invdate: "cell11", amount: "cell12", tax: "cell13", total: "1234", note: "somenote "},
· {Invid: "2", invdate: "cell21", amount: "cell22", tax: "cell23", total: "2345", note: "Some note "},
·...
·]
In this example, the property value of ID is "Invid ".
Once this attribute is set to false, we do not need to assign values to all the name values defined in colmodel. Because the element is searched by name, the sorting result is not specified by colmodel.
User Data)
In some cases, we need to return some parameters from the server, but do not want to directly display them in the Table. Instead, we want to display them elsewhere. Then we need to use the userdata tag.
· Jsonreader :{
·...
· Userdata: "userdata ",
·...
·}
·{
· 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"]},
·...
·]
·}
On the client side, we can obtain the additional information in the following two ways:
1. jquery ("grid_id"). getgridparam ('userdata ')
2. jquery ("grid_id"). getuserdata ()
3. jquery ("grid_id"). getuserdataitem (key)
[Switch] jqgrid learning data