I am using the jqGrid plug-in and at one point I need to refresh the grid and set the selected row to match the record that I am showing in detail on another section of the page. I have the following code but it does not work:
$("#AllActions").trigger("reloadGrid").setSelection(selectedRow);
The selectedRow parameter comes from an event handler that gets called when the data is changed and the grid needs to be updated.
I’m pretty sure that the problem is that the grid is not loaded when the selection is being set, because if I put a call to alert() between the calls to trigger() and setSelection(), it works.
I would be grateful for any advice.
[Edit]Looks like jqGrid's setSelect does not work after reloadGrid is related but did not get resolved.[/Edit]
Firts of all you should save rowid of the old selection in a variable, then call
$("#AllActions").trigger("reloadGrid")and inside ofloadCompleteevent handler set selection with respect of$("#AllActions").setSelection(rowid).Don’t forget to set option
scrollrows:trueof the jqGrid, to be sure that the selected row will be visible.