如何在 jqgrid 中读取 userData? [英] How to read userData in jqgrid?

查看:31
本文介绍了如何在 jqgrid 中读取 userData?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 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 中:

and in 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 (not for 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": [...] }

注意:输入数据中的默认属性必须是 userdataNOT userData 就像你现在拥有的一样.您可以覆盖输入属性的默认名称 jsonReader: {userdata: "userData"}jsonReader: {userdata: "myData"} 如果您使用 userDatamyData 作为您的 附加数据.

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 中显示页脚.您可以将这些数据用于您的任何其他建议.在 another answer 中展示了如何使用 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<加载数据之后/code> 将被删除,因此您必须将其保存在外部对象中.

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 事件句柄你可以通过 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆