jqgrid reloadGrid with loadonce set to true
Asked Answered
A

4

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.

Alternately answered 22/3, 2011 at 20:50 Comment(0)
O
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.

Opine answered 22/3, 2011 at 21:37 Comment(18)
@Opine 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 dataConservative
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 ?Carlyle
@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?Opine
i am trying to achieve is in this question #12901021. basically once the data is loaded after search , i want to make the pagination work locally , my datatype is json initiallyCarlyle
@Hunt: I read your question before and reread it one more time, but I can't understand what you really need. If you implemented both server side paging and searching on the server side why you could need "hybrid pagination"? Your question have too many unclear things for me. You don't posted any jqGrid code and it makes interpreting of your question very difficult. The problem that jqGrid has many alternative ways to implement the same things. For example which kind of searching you use? Do you use loadonce: true or not? Do you use virtual scrolling (scroll: 1) or not and so on.Opine
@Migs: You are welcome! By the way you can use additionally beforeRefresh (see the answer)Opine
@Opine : " If you want refresh the grid data from the server one more time you should set datatype to its original value. " I think it works for more than one time right ? I can continuously reload the table with this right. Actually the problem I had is I used loadonce:true; , but then I can't reload it. When I used loadonce:false; then reloading works, but sorting wont work. With resetting the datatype:'xml' when reloading this problem got solved.Context
@prime: Sorry, but you should describe more exactly what you do and what version of jqGrid from which fork of jqGrid (free jqGrid, Guriddo jqGrid JS or an old jqGrid in version <=4.7) you use. Free jqGrid is the fork which I develop starting the end of 2014. I wrote in the UPDATED part of the answer about the option fromServer: true. If you use it then jqGrid reloads the data from the server everytime when the user click on Reload button of the navigator bar.Opine
@Opine please refer this , I posted it as a question #35271221Context
@Opine Thank you from Turkey :)Pyxidium
loadonce with the fromServer option in reloadGrid is awesome! Thanks Oleg. This is working great for use, as the user will need new data depending on user inputer data which is passed to the server as a parameter, but then all the paging/sorting handled by the freejqGrid client, its perfect and saves a lot of server-side logic.Pitsaw
@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.Opine
This reloads the grid correctly but It doesn't take me to the page I have provided in parameter. Any idea ? why would this happen ?Coenurus
@RohitArora: It's unclear what you do exactly. reloadGrid have page option, which allows you to load specific page. If you have information about the page as a parameter, you can use it as the value for page option of reloadGrid. In general you could still have some other problems. For example, jqGrid verify, that the page value is between 1 and the value of lastpage parameter of jqGrid. If lastpage is too small in your scenario you can need to increase it before calling of reloadGrid with page option.Opine
@Opine I have used the page parameter in reloadGrid as well. it only updates the page value in pagination - data does not get updated for that page. Data remains for 1st page.Coenurus
$("#list").setGridParam({datatype:'json', page:currentPage}).trigger('reloadGrid',[{page: currentPage}]); i am doing this in version 4.4. This gets the updated data from server, reloads the grid but doesn't gets to the pagenumber which I have provided.Coenurus
@RohitArora: Is it good to use version, which is 8 years old? In any way I'd recommend you to debug the problem (you should change from min to src version during debugging). I see many sources of the problem, which you describes. Only debugging can help here. If I guess, I can suppose that the response from the server contains page property with 1 instead of the requested page. In the case the value of page from the server response will overwrite the local page value.Opine
Thanks @Oleg! Yeah I know Its old but client doesn't want it to change right now or purchase any. Finally, I debugged it and fixed the issue.Coenurus
A
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

Academy answered 26/2, 2013 at 12:39 Comment(0)
K
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 !

Karakorum answered 15/1, 2015 at 11:52 Comment(0)
C
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.

Chancery answered 25/2, 2017 at 15:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.