简体   繁体   English

Jqgrid检索所有数据但行为异常

[英]Jqgrid retrieves all data but have strange behavior

In jqgrid I use this part of code to get all data from my jqgrid table: 在jqgrid中,我使用这部分代码从jqgrid表中获取所有数据:

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. 当我console.log allRowsInGrid时,它显示所有数据并显示表数据计数的实际长度。 But then I try to use this array (allRowsInGrid) it show only data that I see on the screen. 但是,然后我尝试使用此数组(allRowsInGrid),它仅显示我在屏幕上看到的数据。 Furthermore, if I try to console.log allRowsInGrid.length it shows length of data that I see. 此外,如果我尝试console.log allRowsInGrid.length,它会显示我看到的数据长度。 I use json datatype and loadonce: true. 我使用json数据类型和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'. 问题不在于您在做什么 ,而在于何时 何地使用“ getGridParam”,“数据”。 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. 例如,您可以在loadComplete内部或beforeProcessing回调内部使用。 I'd recommend you to read the old answer additionally, which describes the differences between loadComplete and gridComplete . 我建议您另外阅读旧的答案 ,它描述了loadCompletegridComplete之间的区别。 In the most cases gridComplete isn't the good choice. 在大多数情况下, gridComplete不是一个好选择。

Moreover, loadComplete will be called not only after the first loading from the server. 而且, 不仅在第一次从服务器加载后 ,将调用loadComplete 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. 如果从服务器加载数据后需要一次执行某些操作,则在beforeProcessing回调之前是好的。 It contains full data returned from the server before the data will be processed by jqGrid. 它包含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. 例如,可以在beforeProcessing回调内部修改或扩展数据,并且jqGrid将看到修改后的数据,就好像它是从服务器返回的一样。

One more option - to place some code in loadComplete inside of if ($(this).jqGrid("getGridParam", "datatype") !== "local") { ... } . if ($(this).jqGrid("getGridParam", "datatype") !== "local") { ... }一种选择-将一些代码放在if ($(this).jqGrid("getGridParam", "datatype") !== "local") { ... }内的loadComplete It allows to do some action after the data loaded from the server have processed and the first page was displayed. 从服务器加载的数据处理完毕并显示第一页 ,它允许执行一些操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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