简体   繁体   中英

jqGrid: reload data from json-string

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.

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
Also it is matter for me, that grid has summary row which defined with userdata .

DOWNLOAD SETUP

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");

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. 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 .

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 ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM