Jqgrid 检索所有数据但有奇怪的行为

Jqgrid retrieves all data but have strange behavior

在 jqgrid 中,我使用这部分代码从我的 jqgrid 中获取所有数据 table:

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

当我 console.log allRowsInGrid 时,它显示所有数据并显示 table 数据计数的实际长度。但是后来我尝试使用这个数组 (allRowsInGrid) 它只显示我在屏幕上看到的数据。此外,如果我尝试 console.log allRowsInGrid.length 它会显示我看到的数据长度。 我使用 json 数据类型和 loadonce: true。尝试了一切但没有任何效果。 这段代码:

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

显示:

有谁知道怎么可能吗?

问题不在于你做什么,而是什么时候哪里你使用'getGridParam','data'。您可以使用数据 after 首先从服务器加载数据。例如,您可以在 loadComplete 内部或 beforeProcessing 回调内部使用。我建议您另外阅读 the old answer,其中描述了 loadCompletegridComplete 之间的差异。在大多数情况下 gridComplete 不是好的选择。

此外,loadComplete 不仅会在第一次从服务器加载 后被调用 。稍后将在每次本地排序、分页和 filtering/searching 时调用它。如果需要在从服务器加载数据后进行一次操作,那么 beforeProcessing 回调很好。它包含从服务器返回的完整数据,然后数据将由jqGrid处理。例如,可以修改或扩展 beforeProcessing 回调中的数据,jqGrid 将看到修改后的数据,就好像它是从服务器返回的一样。

还有一个选择 - 在 if ($(this).jqGrid("getGridParam", "datatype") !== "local") { ... } 内的 loadComplete 中放置一些代码。它允许在从服务器加载的数据处理完并显示第一页后执行一些操作。