0

I have a table filled with data that I want to sort and filter.

I implemented an auto-refresh function, which loads data from the server each time, but I want to restore sort and filter options, which I can do.

I use trigger("reloadGrid",[{current:true}]), setting the datatype to json so that the data are retrieved from the server, in the autorefresh function, and the sort and filter options are used in the loadcomplete method with a setTimeout, as explained in other stackoverflow questions.

That works, but each time the grid refreshes, I see during one second the grid with the full data, not sorted nor filtered, and then the data are locally sorted/filtered.

Given that I want an 5 seconds auto-refresh, is there a way I can prevent the reloadGrid method from displaying the full data when there is a server request but wait for the reload in loadComplete to refresh the display?

Reload used in the autorefresh function :

$("#MyGrid").jqGrid("setGridParam",{url:"list.php", datatype:"json"}).trigger("reloadGrid",[{current:true}]);

Model :

jQuery("#MyGrid").jqGrid({
  url:'list.php',  
  datatype: "json",
  loadonce:true,
  ...
  loadComplete: function(){
    if ($("#MyGrid").jqGrid("getGridParam", "datatype") !== "local") {
      setTimeout(function () {
        $("#MyGrid").jqGrid("setGridParam",{search:srch,postData:post});
      })
    };
  }
Dave L.
  • 9,595
  • 7
  • 43
  • 69
  • Why are using `setTimeout` inside `loadComplete`? Can you link to the question where you got that idea? – Dave L. Mar 05 '13 at 18:58
  • Hi ! The question where I got this idea can be found here : http://stackoverflow.com/a/14468880/2136486. If I'm not wrong, by doing this, the reload inside loadcomplete is waiting that data from server are correctly retrieved. Am I correct ? – user2136486 Mar 05 '13 at 23:50

1 Answers1

0

You can use setInterval JavaScript function to do automatic refreshing

var grid = $("#list"),
intervalId = setInterval(
    function() {
        grid.trigger("reloadGrid",[{current:true}]);
    },
    60000); // Every 1 min

to stop the grid reload you can use one more JavaScript function:

clearInterval(intervalId);

In the "reloadGrid" I use less known parameter current:true which is described here to preserve the current selection in the grid.

You can see the Reload Jqgrid by given interval

Community
  • 1
  • 1
Amit Garg
  • 3,867
  • 1
  • 27
  • 37