jqGrid:从json-string重新加载数据 [英] jqGrid: reload data from json-string

查看:75
本文介绍了jqGrid:从json-string重新加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,SO上存在几个类似的问题,但是尽管如此,我还是创建了这个问题,原因是:
-我还是不明白:)
-我想创建一个可能涵盖更完整问题的主题.

I know, that there is several similar questions are exists on SO, but despite it I creating this question because:
- I still don't get it :)
- I want to create a topic that possibly will cover a problem more complete.

我以简化的方式重建了生产设置,可以通过下面的链接获得它. 简而言之-我有一个简单的jqGrid,它使用jsonstring作为dataType,并使用datastr和JSON数据.然后通过触发:

I reconstructed my production setup in simplified way, it available by link below. In short - I have simple jqGrid, that uses jsonstring as dataType, and datastr with JSON data. And then by firing this:

$("#grid").setGridParam({'datastr': myNewData}).trigger('reloadGrid');

我正在尝试在网格中重新加载数据,但是它不起作用. 我想念什么?

Im trying to reload data in grid, but it just doesnt work. What am I missing?

ps
对我来说也很重要,该网格具有用userdata定义的摘要行.

ps
Also it is matter for me, that grid has summary row which defined with userdata.

推荐答案

很少真正需要使用datatype值,而"local""json""jsonp""xml"除外.其他datatype的大多数用法可以很容易地替换为树的主要数据类型.如果使用"jsonstring""xmlstring""clientSide",则在加载数据后,datatype将被更改为"local" (请参见,则可以按使用情况修复重新加载

It's very seldom that you really need to use datatype which values other as "local", "json", "jsonp" or "xml". Most usage of other datatype can be easy replace to the tree main datatypes. If you use "jsonstring", "xmlstring" or "clientSide" then the datatype will be changed to "local" after loading of data (see the line of source code for example). So if you really need to use datatype: "jsonstring" you can fix reloading by usage

$("#grid").setGridParam({
    datastr: myNewData,
    datatype: "jsonstring" // !!! reset datatype
}).trigger("reloadGrid");

此外,我可以看到您使用了jqGrid的pager: false选项.这是错误的选择.如果您不需要使用本地数据分页,建议您

Additionally I could see that you used pager: false option of jqGrid. It's wrong option. If you don't need to use local paging of data I recommend you

  1. 不包括和pager选项.默认值pager: ""已经可以.
  2. include rowNum参数具有足够大的值,例如rowNum: 10000. rowNum的默认值为20.因此,如果您不想仅显示输入数据的前20行,则应增加rowNum的值.
  1. don't include and pager option. Default value pager: "" is already OK.
  2. include rowNum parameter with some large enough value like rowNum: 10000. Default value of rowNum is 20. So if you don't want to display only the first 20 rows of the input data you should increase the value of rowNum.

最后一条建议:您应该包括sorttype: "integer"(请参见文档)保存到包含整数值的列.如果用户单击列标题,它将修复数据排序.您还应该考虑使用列模板(请参见旧答案).

The last recommendation: you should include sorttype: "integer" (see the documentation) to columns which holds integer values. It will fix sorting of data if the user clicks on the column header. You should consider to use column templates too (see the old answer).

这篇关于jqGrid:从json-string重新加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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