如何读取jqgrid中的userData?
我需要将 userData
传递给 jqgrid,但找不到任何如何执行此操作的示例。这是我的尝试:
从服务器发送:
{ total: 25,
page: currentpage,
userData: {foo: 'bar'},
rows: myRows }
在 jqgrid 中:
var data = jQuery("#grid").getGridParam('userData');
如何发送 userData
并从 jqgrid 读取它?
编辑:我知道我的 userData
正在发送,因为我可以在 Fiddler。我想我只是卡在如何在客户端阅读它。
I need to pass userData
to jqgrid, but can't find any examples of how to do this. Here's my attempt:
Sent from the server:
{ total: 25,
page: currentpage,
userData: {foo: 'bar'},
rows: myRows }
and in jqgrid:
var data = jQuery("#grid").getGridParam('userData');
How can I send userData
and read it from jqgrid?
EDIT: 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说,
userData
的用法非常简单。 jqGrid 支持您从服务器发送任何附加数据,这些数据将与 jqGrid 数据一起保存。因此,如果 jqGrid 解析从服务器返回的数据,那么它只会查找userdata
(不是 foruserData
!!!)并保存在内部参数userData
。请注意:输入数据中的默认属性必须是
userdata
并且NOTuserData
就像您当前所拥有的那样。如果您使用userData<,则可以覆盖输入属性
jsonReader: {userdata: "userData"}
或jsonReader: {userdata: "myData"}
的默认名称/code> 或myData
作为属性名称,并使用 其他数据。userData
的标准用法之一是 在 jqGrid 中显示页脚。您可以将这些数据用于您的任何其他建议。在另一个答案中显示了如何使用userData< /code> 从服务器加载数据后直接选择一些行。
如果您使用
loadonce:true
参数,则userData
的使用会有点棘手,因为在第一次从参数userData
加载数据后将被删除,因此您必须将其保存在外部对象中。当然,只有在加载数据后,您才能通过
jQuery("#grid").getGridParam('userData')
访问userData
。因此,您应该在 loadComplete 事件句柄内执行此操作或稍后。顺便说一句,在 loadComplete 事件句柄内部,您可以访问通过 loadComplete 事件。因此您可以读取任何其他附加数据并将其保存在某处。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 foruserdata
(not foruserData
!!!) and save is in the internal parameteruserData
.Be careful: the default property in the input data must be
userdata
and NOTuserData
like you currently have. You can overwrite the default name of input propertyjsonReader: {userdata: "userData"}
orjsonReader: {userdata: "myData"}
if you useuserData
ormyData
as the property name with your additional data.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 useuserData
to select the some row/rows directly after the loading data from the server.If you use
loadonce:true
parameter, the usage ofuserData
will be a little more tricky because after the first load the data from the parameteruserData
will be deleted, so you have to save there in the external object.Of cause you can access the
userData
with respect ofjQuery("#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 throughdata
parameter of loadComplete event. So you can read any other additional data and save there somewhere.jqGrid 默认接受这种格式的 JSON。
并设置 jqgrid 选项,您将执行以下操作:
jqGrid by default accepts JSON in this format.
and setting up the jqgrid options you would do something like this: