如何在jqgrid中读取userData? [英] How to read userData in jqgrid?
问题描述
我需要将userData
传递给 jqgrid ,但找不到有关如何执行此操作的示例.这是我的尝试:
I need to pass userData
to jqgrid, but can't find any examples of how to do this. Here's my attempt:
从服务器发送:
{ total: 25,
page: currentpage,
userData: {foo: 'bar'},
rows: myRows }
和在jqgrid中:
var data = jQuery("#grid").getGridParam('userData');
如何发送userData
并从jqgrid读取它?
How can I send userData
and read it from jqgrid?
我知道我的userData
已发送,因为我可以在提琴手中看到它.我想我只是在客户端阅读方法上停留.
I know my userData
is being sent, because I can see it in Fiddler. I think I'm just stuck on how to read it on the client side.
推荐答案
通常,userData
的用法非常简单. jqGrid支持您从服务器发送将与jqGrid数据一起保存的任何其他数据.因此,如果jqGrid解析了从服务器返回的数据,则它只会查找userdata
(对于userData
而言不是不是),并且保存在内部参数userData
中.
In general the usage of userData
is pretty simple. jqGrid gives you support to send from the server any additional data which will be saved together with the jqGrid data. So if jqGrid parses the data returned from the server then it just looks for userdata
(not for userData
!!!) and save is in the internal parameter userData
.
{ "total":25,
"page":1
"records":107,
"userdata": {"foo": "bar"},
"rows": [...] }
请注意:输入数据中的默认属性必须为userdata
,并且不能 userData
,就像您当前所拥有的一样.如果将userData
或myData
用作属性名称,并且您的
Be careful: the default property in the input data must be userdata
and NOT userData
like you currently have. You can overwrite the default name of input property jsonReader: {userdata: "userData"}
or jsonReader: {userdata: "myData"}
if you use userData
or myData
as the property name with your additional data.
userData
的标准用法之一是在jqGrid中显示页脚.您可以将数据用于其他任何提议.在另一个答案中,展示了如何使用userData
选择直接从服务器加载数据之后的一些行/行.
One from the standard usage of userData
is for displaying of the footer in the jqGrid. You can use the data for any your other propose. In another answer it is shown how to use userData
to select the some row/rows directly after the loading data from the server.
如果使用loadonce:true
参数,则userData
的用法会有些棘手,因为在第一次加载后,参数userData
中的数据将被删除,因此您必须将其保存在外部对象中
If you use loadonce:true
parameter, the usage of userData
will be a little more tricky because after the first load the data from the parameter userData
will be deleted, so you have to save there in the external object.
当然,只有在数据加载后,您才可以相对于jQuery("#grid").getGridParam('userData')
访问userData
.因此,您应该在 loadComplete 事件句柄内执行此操作或更高版本.通过 loadComplete 事件句柄,您可以通过
Of cause you can access the userData
with respect of jQuery("#grid").getGridParam('userData')
only after the data are loaded. So you should do this inside of loadComplete event handle or later. By the way inside of loadComplete event handle you can access to all data which are send to you from the server through data
parameter of loadComplete event. So you can read any other additional data and save there somewhere.
这篇关于如何在jqgrid中读取userData?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!