JSON and jqGrid. What is “userdata”?

白昼怎懂夜的黑 提交于 2019-11-26 17:08:06

问题


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?


回答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.




回答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.



来源:https://stackoverflow.com/questions/3128837/json-and-jqgrid-what-is-userdata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!