I wrote recently an answer to the question "jqGrid display default “loading” message when updating a table / on custom update". While writing the answer I thought: why does he use the addJSONData() function for refreshing data in the grid instead of changing the URL with respect to setGridParam() and refreshing jqGrid data with respect to trigger('reloadGrid')? At the beginning I wanted to recommend using 'reloadGrid', but after thinking about this I understood that I am not quite sure what the best way is. At least, I can't explain in two sentences why I prefer the second way. So I decided that it could be an interesting subject of a discussion.
So to be exact: We have a typical situation. We have a web page with at least one jqGrid and some other controls like combo-boxes (selects), checkboxes etc. which give the user possibilities to change the scope on information displayed in a jqGrid. Typically we define some event handler like jQuery("#selector").change(myRefresh).keyup(myKeyRefresh)
and we need to reload the jqGrid container based on user's choices.
After reading and analyzing the information from additional user's input we can refresh the jqGrid container in at least two ways:
- Make call of
$.ajax()manual and then inside of success or complete handle of$.ajaxcalljQuery.parseJSON()(oreval) and then call addJSONData function of jqGrid. I found a lot of examples on stackoverflow.com which use addJSONData. - Update url of jqGrid based on user's input, reset current page number to 1 and optionally change the caption of the grid. All these can be done with respect to setGridParam(), and optionally setCapt