Json of Jqgrid data

Source: Internet
Author: User
Tags jqgrid

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.