Can start ("reloadGrid") work when "loadonce: true" in jqGrid?

The jqGrid source file I use is listed at the top of the version as jqGrid 4.4.0 , date as Date 2012-06-14

This wiki page says trigger("reloadGrid") ,

Reloads the grid with the current settings. This means that a new request is send to the server if datatype is xml or json. This method should be applied to an already-constructed grid. Pay attention that this method does not change HEADER information, that means that any changes to colModel would not be affected. You should use gridUnload to reload new configuration with different colModel. IT WORK ONLY IF loadonce: false !!!

And yes, he says "ONLY WORKS ONLY IF loadonce: false !!!"

And this SO answer is suggested by some hack for this. It says:

If you use loadonce:true jqGrid change the datatype parameters to 'local' after the first load of data from the grid. All next grid reloading (sorting, paging, filtering) works local. If you want refresh the grid data from the server one more time you should set datatype to its original value ('json' or 'xml').

So, this answer actually solved the problem that I ran into. I had jqGrid with loadonce:true . (I'm worried about sorting here, and it works great). but then I had to change the code a bit to reload jqGrid with new server data. (the user can change some details and update the table so that jqGrid must reload recently acquired data from the server). Unfortunately, this did not work until I changed loadonce:true to loadonce:false .

I called reboot like this,

 $("#tableGrid").setGridParam({url:'myUrl'}).trigger('reloadGrid'); 

Now the reboot was fine. BUT sorting disappeared :(

And then I saw that SO would respond and change it to something like this,

I set loadonce:true when initializing the grid. and is called reboot, as shown below.

 $("#tableGrid").setGridParam({url:'myUrl',datatype:'xml'}).trigger('reloadGrid'); 

after that, all sorting was perfect, and the user could also reload the grid.

Is this approach right? I think he solved the problem , but right? because the documentation says you cannot reload when loadonce:true ?

+2
javascript jqgrid
08 feb. '16 at 13:21
source share
1 answer

First of all, I would strongly recommend that you upgrade the jqGrid that you are using from version 4.4.0 to the free jqGrid 4.12.1. Free jqGrid is a jqGrid fork that I have been developing since the end of 2014. See the message and the link from the UPDATED part for more information. You should understand that jqGrid 4.4.0 is really a retro version. It was published during jQuery version 1.4.3. This was the time when IE9 was the latest version of Internet Explorer, but IE6-IE8 were the most commonly used versions. Now we have one more point in web development.

It is important to understand what to do loadonce: true and what to do .trigger('reloadGrid') .

jqGrid supports local data storage inside JavaScript objects. You can use datatype: "local" , provide data using the data parameter, and then work with the data using a local search call, sorting and filtering the data. You can change the page size ( rowNum ), page number ( page ) and sorting options ( sortname , sortorder ) and reload the current displayed page using the new parameters by triggering the reloadGrid event. jqGrid sorts the data and displays the requested page. Therefore, it is important to understand that .trigger('reloadGrid') also works with local data.

If you use datatype:'xml' along with loadonce: true , the server should return all the data . Data should be sorted by the requested parameters sortname , sortorder (parameters sidx and sord the server request). Thus, jqGrid fills the internal data parameter with all the data . jqGrid displays the first page of returned data (based on page size of rowNum and page number of page ). Finally (after handling the loadComplete ) jqGrid changes the original datatype ( "xml" in your case) to datatype: "local" . Now the user can use local paging, sorting and filtering data without any connection to the server. For each sort, paging and filtering jqGrid uses the reloadGrid event to display the corresponding data page.

If you need to reload data from the server, you just need to restore the original value of the datatype parameter and call reloadGrid . for example

 $("#tableGrid").setGridParam({datatype:'xml'}).trigger('reloadGrid'); 

If your server is correctly implemented, the user will see the requested data page, and all local data will be updated. After the page is displayed, the datatype will be changed to datatype:'local' .

If you are using the current free jqGrid, you can use the following options

 loadonce: true, forceClientSorting: true, navOptions: { reloadGridOptions: { fromServer: true } } 

The forceClientSorting: true option removes the requirement from the server to provide sorted data. Free jqGrid can sort the data returned from the server. If you use navGrid , it adds a Refresh / Reboot button. The navOptions: { reloadGridOptions: { fromServer: true } } option changes the behavior of the button so that the data will be reloaded from the server if the user clicks on the button. No manual modification of the datatype is required.

+2
Feb 08 '16 at 14:23
source share



All Articles