How to refresh the data in a jqGrid?
Asked Answered
B

4

44

I have been trying to get a grid to be updated from the datasource when a button is pushed.

So I have in the click event something like this:

$('#grid').jqGrid('trigger','reloadGrid');

However this does not work and I get an error thrown for unknown method 'trigger'

I have also tried

$('#grid').jqGrid('trigger("reloadGrid")');

How would I execute this function?

Beker answered 28/6, 2010 at 18:38 Comment(0)
N
85
$('#grid').trigger( 'reloadGrid' );
Nikkinikkie answered 28/6, 2010 at 18:42 Comment(4)
I do wish they would change the documentation for jqGrid as right now it is a bit deceiving..Beker
The bind() and trigger() methods are part of the jQuery core, FYINikkinikkie
yes they are but their documentation does not make that obvious and the reloadGrid function is not listed in green as somethin requiring a "special method of calling"Beker
Is this method of refreshing memory-leak-safe ?Weismannism
S
23

This worked for me.

jQuery('#grid').jqGrid('clearGridData');
jQuery('#grid').jqGrid('setGridParam', {data: dataToLoad});
jQuery('#grid').trigger('reloadGrid');
Statfarad answered 29/1, 2015 at 7:12 Comment(1)
Where did you put this code? Could you be more specific please, I'm newbie on it. Tks.Uppermost
P
2

Try this to reload jqGrid with new data

jQuery("#grid").jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid');
Parnassian answered 12/5, 2017 at 17:34 Comment(0)
X
0
var newdata= //You call Ajax peticion//

$("#idGrid").clearGridData();

$("#idGrid").jqGrid('setGridParam', {data:newdata)});
$("#idGrid").trigger("reloadGrid");

in event update data table

Xanthe answered 13/7, 2018 at 21:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.