19

I am using two jqgrids in one page. second grid i used loadonce: true since i need column sort in the second grid. i need to reload both grids after a server post back. (need to show updated value in the second grid). first grid reload fine since it won't use the loadonce attribute. my question is can we use loadonce attribute and reloadGrid together? ( by setting loadonce attribute dynamically to the grid) or else do i need to go for a server side sorting in this case? please advice. Thanks in advance.

0

4 Answers 4

72

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'). For example:

$("#list").setGridParam({datatype:'json', page:1}).trigger('reloadGrid');

UPDATED: Free jqGrid supports fromServer: true option of reloadGrid starting with the first release (starting with version 4.8). So one can use the code like

$("#list").trigger("reloadGrid", { fromServer: true, page: 1 });

to do the same as above. The main advantage: such code works fine with any initial value of datatype ("json", "jsonp", "xml" and so on). Free jqGrid saves original value of datatype inside of internal dataTypeOrg before changing it to "local".

One more helpful option of free jqGrid is the parameter reloadGridOptions of navGrid, which allows to specify default options of reloadGrid. Thus one can use for example

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

options of jqGrid, which set defaults for navGrid additionally. As the result the click on "Reload" button of navigator bar will reload the grid from the server instead of local reloading.

19
  • @Oleg and Sam , do either of you have any thoughts on this question ? I'm trying to refresh my data from the server every 10 seconds and make sure I have the latest data
    – blong
    Aug 18, 2011 at 14:35
  • Issue was freaking me out... Thanks for Helping :)
    – pinaldesai
    Mar 3, 2012 at 5:21
  • i want to convert it to local once the data is loaded , so i use jQuery("#memberGrid").setGridParam({datatype:'local', data:mdata}).trigger('reloadGrid'); in loadComplete but the page is not changing locally ?
    – Hunt
    Oct 15, 2012 at 18:36
  • @Hunt: Sorry, but I don't understand what you do and what you want to do. Do you use loadonce: true? Which value has datatype initially in your jqGrid? What is your goal?
    – Oleg
    Oct 15, 2012 at 18:46
  • 1
    @jeffery_the_wind: You are welcome! I'm glad that you find the option helpful. I tried to implement not only large new features in free jqGrid, but to make minor changes, which makes the usage of jqGrid easyier. fromServer: true and forceClientSorting: true are two options, which could be very helpful in loadonce: true scenario.
    – Oleg
    Aug 7, 2017 at 14:30
0

Nice was trying for last one week , solution is perfect use

jQuery("#datalist").jqGrid().setGridParam(
    {
        datatype:'xml', 
        page:1, 
        url : '<%=request.getContextPath()%>/PreviewReport?cmd=1&fromdate='+vfromDate+'&todate='+vtoDate+'&status='+vstatus+'&keyword='+vkeyword+'&mdn='+vmdn+'&filetype='+vfiletype
    }
).trigger("reloadGrid");

to reload the data using loadonce:false

0
0

Just to say, for me, the following line wasn't enough, to refresh the data in my loadonce:true jqGrid:

$("#MikesGrid").jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid');

After calling that line, I tried to call my code which loaded my JSON data and populated the jqGrid with it, but it didn't refresh the rows in my grid.

My solution was to forcibly unload the jqGrid, and then call my function to recreate it.

$("#MikesGrid").jqGrid('GridUnload');

Perhaps I was just unlucky.

Btw, when I get a chance, I'll document how I wrote a generic JavaScript function to add two buttons to any jqGrid, one to refresh the (loadonce) data, and a second button to export the jqGrid data into a real Excel file, using my library:

Export jqGrid to an Excel file

I like reuseable code !

0
$("#shoppingCatalog").jqGrid('GridUnload');

Will remove the structure and then your code can rebuild the grid with the data from the next server call-back.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.