1

We are using jgGrid and it works perfectly fine. Let me explain how the grid is setup, we are fetching json data from server, loadonce: true.

Now we want to update the grid every 20 seconds, so

setInterval(function () {
                $("#jqGrid").setGridParam({ datatype: 'json', page: 1 }).trigger('reloadGrid', [{ current: true }]);

            }, 20000);

This is working fine. Issue is that, it entirely refreshes the grid, we want to update the data which is changed. I mean if there is change in only one cell of a column, only that cell should be changed.

Having entire grid refresh is causing issue on sorting and search filter. It replaces everything after 20 seconds.

Thanks in advance

Johny Bravo
  • 414
  • 9
  • 34

1 Answers1

1

The most simple way to solve your problem would be the usage of beforeProcessing callback which returns false if the data are not changed. It will prevent reloading of the grid in case if the data returned from the server are unchanged (compared with the previous response). I described the scenario in details in the answer. The main problem is: how to determine that the returned data are the same. In the referenced old answer I calculated MD5 cache from the data on the server side and set the value as Etag. Alternatively you can use CryptoJS to make the calculation on the client side. The 3-d parameter of beforeProcessing callback is jqXHR, which is a superset of the XMLHTTPRequest object. It contains for example responseText property, which simplifies MD5 calculation. By usage of jqXHR.getResponseHeader("ETag") you have access to the ETag HTTP header.

Reloading of the whole grid makes typically no performance problems. It's important, that modification of one cell of the grid follows to reflow or probably changing position of another elements on the page. Reloading of the whole grid is implemented as one assigning of <tbody> of the grid (if you use fill the grid correctly and if you use gridview: true option). It seems to many additional work, but it could be more quickly on the practice as sequential changing of multiple cells in multiple rows of the grid.

In any way I'd recommend you to start with implementing beforeProcessing callback, which returns false in case of unchanged server data. Only if you would have some real performance problem then you should analyse the performance problem detailed, and probably make more deep changes in your existing code.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • thanks for the comment. I will try to implement beforeProcessing callback – Johny Bravo Jun 10 '16 at 11:13
  • https://github.com/tonytomov/jqGrid/issues/789 @tonytomov has already answered my question here but still I would love to give beforeProcessing a shot. – Johny Bravo Jun 10 '16 at 11:22
  • 1
    @JohnyBravo: You are welcome! I wrote in my answer that reloading of jqGrid could be even more effective as usage of `setRowData`. Moreover you don't included enough details in your question. For example, you use `rowNum: 5, loadonce: true` and you try to use `setRowData` to update the data. It will work only with the data **on the current page**. If the data are changed on another page then `setRowData` will not work. Additionally, changing the data on another page and reloading can change the order of rows (based on `sortname`) and the solution with `setRowData` will work incorrectly. – Oleg Jun 10 '16 at 11:32
  • thanks for the inputs. Yes works only with the data on the current page. Is there something we can do with this using setRowData, it updates the values on current page but on other page it doesn't refresh the values – Johny Bravo Jun 10 '16 at 12:01
  • @JohnyBravo: You can use `getLocalRow` to update the data on another page. – Oleg Jun 10 '16 at 12:27
  • @JohnyBravo: I repeat that changing of the data in the column, by which the data are sorted, **required** reloading of the grid. You will display wrong sorted data if you would just use `setRowData` and `getLocalRow`. I'd recommend you just use `reloadGrid`, skipping the reloading if no data are changed. You will get clear and safe solution in the way. – Oleg Jun 10 '16 at 12:44