如何读取jqgrid中的userData?

发布于 2024-09-26 01:20:09 字数 586 浏览 0 评论 0原文

我需要将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悲欢浪云 2024-10-03 01:20:09

一般来说,userData 的用法非常简单。 jqGrid 支持您从服务器发送任何附加数据,这些数据将与 jqGrid 数据一起保存。因此,如果 jqGrid 解析从服务器返回的数据,那么它只会查找 userdata不是 for userData!!!)并保存在内部参数userData

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

请注意:输入数据中的默认属性必须是 userdata 并且NOT userData 就像您当前所拥有的那样。如果您使用 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 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 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.

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.

最好是你 2024-10-03 01:20:09

jqGrid 默认接受这种格式的 JSON。

{"rows":
    [{"foo":"bar"}]
}

并设置 jqgrid 选项,您将执行以下操作:

$("#cashflow-sheet").jqGrid({
    url:'bbc-json.html',
    datatype: "json",
        ...

jqGrid by default accepts JSON in this format.

{"rows":
    [{"foo":"bar"}]
}

and setting up the jqgrid options you would do something like this:

$("#cashflow-sheet").jqGrid({
    url:'bbc-json.html',
    datatype: "json",
        ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文