简体   繁体   中英

Jqgrid retrieves all data but have strange behavior

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: 在此处输入图片说明

Does anyone know how it can be possible?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM