JSON data
The jsonreader needs to be defined to correspond to the data returned by the server, with its default values:
· Jsonreader: {
· Root: "Rows",
· Page: "Page",
· Total:
· Records: "Records",
· Repeatitems:true,
· Cell: "Cell",
· ID: "id",
· UserData: "UserData",
· Subgrid: {root: "Rows",
· Repeatitems:true,
· Cell: "Cell"
· }
The data format that is returned by the server side is:
· {
· Total: "XXX",
· Page: "YYY",
· Records: "Zzz",
· Rows: [
· {ID: "1", cell:["Cell11", "cell12", "Cell13"]},
· {ID: "2", cell:["Cell21", "cell22", "Cell23"]},
· ...
· ]
· }
Properties of the Jsonreader
Total |
Total pages |
Page |
Current page |
Records |
Number of records queried |
Rows |
An array containing the actual data |
Id |
Row ID |
Cell |
All cells of 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
Indicates that the data for each row can be duplicated, and if set to False, the element is searched by name in the returned data, which is the name of the 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 id attribute value is "Invid".
Once this property is set to False, we do not have to assign all the name values defined in the Colmodel. Because the search element is by name, his sort is not the sort result specified by Colmodel.
User Data
In some cases, we need to return some parameters from the server side but do not want to show them directly to the table, but want to display 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"]},
· ...
· ]
· }
At the client we can get these additional information in the following two ways:
1. JQuery ("grid_id"). Getgridparam (' UserData ')
2. JQuery ("grid_id"). Getuserdata ()
3. JQuery ("grid_id"). Getuserdataitem (Key)