0

In jqgrid I use this part of code to get all data from my jqgrid table:

var allRowsInGrid = $('#table_outgoing_calls_report').jqGrid('getGridParam','data');

When I console.log allRowsInGrid it shows all data and shows actual length of table data count. But then I try to use this array (allRowsInGrid) it show only data that I see on the screen. Furthermore, if I try to console.log allRowsInGrid.length it shows length of data that I see. I use json datatype and loadonce: true. Tried everything but nothing works. This piece of code:

 var allRowsInGrid = $('#table_outgoing_calls_report').jqGrid('getGridParam','data');
        console.log(allRowsInGrid);
        console.log(allRowsInGrid.length);

shows this: enter image description here

Does anyone know how it can be possible?

Den B
  • 843
  • 1
  • 10
  • 26
  • The problem is not *what you do*, but *when* and *where* you use `'getGridParam','data'`. You can use `data` **after** the data are loaded first from the server. You can use there for example inside of `loadComplete` or inside of `beforeProcessing` callback. Please write additionally *in all questions about jqGrid* **the version** of jqGrid, which you use and **the fork** ([free jqGrid](https://github.com/free-jqgrid/jqGrid), commercial [Guriddo jqGrid JS](http://guriddo.net/?page_id=103334) or an old jqGrid in version <=4.7). – Oleg May 16 '18 at 10:27
  • @Oleg, you are totally right. I just used getGridParam in gridComplete function. Thanks a lot. You can answer the question and I mark the answer as correct. – Den B May 16 '18 at 10:36

1 Answers1

2

The problem is not what you do, but when and where you use 'getGridParam','data'. You can use data after the data are loaded first from the server. You can use there for example inside of loadComplete or inside of beforeProcessing callback. I'd recommend you to read the old answer additionally, which describes the differences between loadComplete and gridComplete. In the most cases gridComplete isn't the good choice.

Moreover, loadComplete will be called not only after the first loading from the server. It will be called later on every local sorting, paging and filtering/searching. If one needs to make some actions once after loading the data from the server then beforeProcessing callback is good. It contains full data returned from the server before the data will be processed by jqGrid. One can for example modify or extend the data inside of beforeProcessing callback and jqGrid will see the modified data as if it was returned so from the server.

One more option - to place some code in loadComplete inside of if ($(this).jqGrid("getGridParam", "datatype") !== "local") { ... }. It allows to do some action after the data loaded from the server have processed and the first page was displayed.

Oleg
  • 220,925
  • 34
  • 403
  • 798