JSON and jqGrid. What is "userdata"?

12,276

Solution 1

It is very easy to explain. The server produce a data which will be used to fill the grid. The data can be paged. So in the URL send to the server we can find rows=10&page=2, which means "give me the second page of data, when the page size is 10 rows". These additional parameters will be added to the main url "server.php?q=2" defined as one of jqGrid parameters. The server give back 10 or less rows. In case of http://www.trirand.com/blog/jqgrid/server.php?q=2&rows=10&page=2 url the server gives back only 3 last rows (from the total 10)

{"page":"2",
 "total":2,
 "records":"13",
 "rows":[
   {"id":"11","cell":["11","2007-10-06","Client 1","600.00","120.00","720.00",null]},
   {"id":"12","cell":["12","2007-10-06","Client 2","700.00","140.00","840.00",null]},
   {"id":"13","cell":["13","2007-10-06","Client 3","1000.00","0.00","1000.00",null]}
 ],
 "userdata":{"amount":2300,"tax":260,"total":2560,"name":"Totals:"}
}

Now about your main question: what is "userdata"? There exists an old way to send an additional information from the server to the client together with the main data. It can be absolutely free data. All data received from server will be parsed by jqGrid with respect of so named jsonReader (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_data). A standard JSON reader is defined so, that it read data userdata property from the root of data sent and just save it. This data is accessible with respect of

var myUserData = jQuery("grid_id").getGridParam('userData');

(see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#user_data).

Starting with the version 3.5 of jqGrid it is possible to place an additional last row in the jqGrid which could play "Summary Footer Row" role (see on http://www.trirand.com/blog/jqgrid/jqgrid.html under "New in version 3.5", "Summary Footer Row" example). Now you can see, the url in the example is absolutely the same: "server.php?q=2". So in the first example userdata will not be used, but it will be used in "Summary Footer Row" example.

Solution 2

That seems to be the sum of the columns 'Amount' 'Tax' and 'Total' on the second paginated page assuming that the grid is ordered by the 'Inv No' low to high.

These values do not appear to be being used by that particular grid, but perhaps they are used in one of the other live examples which is why they are there.

Share:
12,276
Earlz
Author by

Earlz

Hello there! My name's Jordan Earls, but most people online know me as "earlz". I'm the lead developer and a co-founder of the Qtum project which brings the Ethereum Virtual Machine (ie, the thing that makes Solidity contracts function) to a UTXO based blockchain similar to Bitcoin. I've been programming since I was 13 and am completely self-taught. Low-level code like assembly and pointer arithmetic is the fun stuff for me. I also make music when I have time even though it's usually awful. Most of my personal projects are open source and BSD licensed. The majority of them are at bitbucket with the rest of them being listed on github Also, you can follow me on the twitters @earlzdotnet

Updated on June 28, 2022

Comments

  • Earlz
    Earlz almost 2 years

    I'm having trouble understanding what all of the fields in a JSON datasource for a jqGrid means and I am not seeing any documentation for it anywhere.

    The example I'm trying to understand is this: http://www.trirand.com/blog/jqgrid/jqgrid.html and then the first example under "JSON Data"

    The JSON data can be accessed here: http://www.trirand.com/blog/jqgrid/server.php?q=2&rows=10&page=2

    One of the things that confuse me in the JSON is this snipplet:

    "userdata":{"amount":1520,"tax":202,"total":1724,"name":"Totals:"}
    

    What exactly is this doing?