0

If I load or reload jqGrid on a GET that takes a while to process and then make a subsequent call to $("#myJqGrid").trigger("reloadGrid"); while that first process is being called, then the second call never issues GET request. Is there a way I can queue them up or cancel them? Or any other ideas for handling this? Don't want to confuse the user with a bunch of queued requests, where they think they are getting a response for a request they just made, but it's the result from the first one.

I don't think this would be so much of an issue for me if there was a clean way to disable jqGrid from making the GET on initial load.

Bradford
  • 4,143
  • 2
  • 34
  • 44

1 Answers1

1

The most easy way to prevent loading of jqGrid initially is to use datatype: 'local' at the initialization time. If you need really fill the grid with the data from the server should should first change the datatype to 'json' or 'xml' with respect of setGridParam and then trigger reloadGrid:

$("#gridId").jqGrid('setGridParam', {datatype: 'json'}).trigger('reloadGrid');

jqGrid has no way to queue Ajax requests. If you really need to make many sequential Ajax requests you should make the next request inside of loadComplete. You can for example create an array of requests, test in loadComplete whether the array is empty. If it's not empty you can call .trigger('reloadGrid') inside of setTimeout callback and call shift method of the array.

In the most cases you don't really need to implement the Ajax queue. See for example the answer as an example.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Changing the data type seems like a hack to me, though. It'd be nice if there was a fetchDataOnFirstLoad option, but with a better name. – Bradford Apr 09 '12 at 17:37
  • @Bradford: I'm not the owner of jqGrid code. You should post all your suggestion to [trirand](http://www.trirand.com/blog/?page_id=393/feature-request/). You should don't forget, that there are currently vary much options already. The new option `fetchDataOnFirstLoad` which you suggest is equivalent to the usage of `datatype: 'local'` and setting `.jqGrid('setGridParam', {datatype: 'json'})` **without** reloading of the grid directly after creating of the grid. So the option which you need means more `dontLoadDataOnCreate`. – Oleg Apr 09 '12 at 17:45