How to read userData in jqgrid?

问题:

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.


答案:

In general the usage of userData is pretty simple. jqGrid give you support to send from the server any additionaldata which will be saved together with the jqGrid data. So if jqGrid parse the data returned from the server it just look for userdata (not for userData!!!) and save is in the internal parameter userData.

{ "total":25, "page":1 "records":107, "userdata": {"foo": "bar"}, "rows": [...] }

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 property jsonReader: {userdata: "userData"} or jsonReader: {userdata: "myData"} if you use userData or myData 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 use userData to select the some row/rows directly after the loading data from the server.

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.

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.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值