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.
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.
jQuery("#memberGrid").setGridParam({datatype:'local', data:mdata}).trigger('reloadGrid');
in loadComplete but the page is not changing locally ? –
Carlyle loadonce: true
? Which value has datatype
initially in your jqGrid? What is your goal? –
Opine json
initially –
Carlyle loadonce: true
or not? Do you use virtual scrolling (scroll: 1
) or not and so on. –
Opine beforeRefresh
(see the answer) –
Opine 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 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 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 fromServer: true
and forceClientSorting: true
are two options, which could be very helpful in loadonce: true
scenario. –
Opine 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 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 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
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 !
$("#shoppingCatalog").jqGrid('GridUnload');
Will remove the structure and then your code can rebuild the grid with the data from the next server call-back.
© 2022 - 2024 — McMap. All rights reserved.