jqGrid在客户端排序

2022-01-19 00:00:00 sorting jquery javascript ajax jqgrid

我有一个自动加载行的树形网格.目标是在客户端上按树列对网格进行排序.

I have a tree-grid with autoloading rows. The goal is to sort the grid by tree column, right on client side.

但每次我单击排序列标题时,它发出一个 Ajax 调用以进行排序,但我只需要使用本地数据进行就地排序.

But each time I click on sort column header, it issues an Ajax call for sorting, but all I need is on-place sorting using the local data.

我是否有不正确的网格参数或树不适用于树列上的客户端排序?

Do I have incorrect grid parameters or doesn't tree work with client-side sorting on tree column?

当前用于排序的 jqGrid 参数是:

Current jqGrid params for sorting are are:

loadonce: true, // to enable sorting on client side
sortable: true //to enable sorting

推荐答案

为了让客户端排序工作,我需要在加载网格后调用 reloadGrid:

To get client-side sorting to work, I needed to call reloadGrid after the grid was loaded:

loadComplete: function() {
    jQuery("#myGridID").trigger("reloadGrid"); // Call to fix client-side sorting
}

我不必在我的应用程序的另一个网格上执行此操作,因为它被配置为使用通过另一个 AJAX 调用检索的数据,而不是直接由网格检索的数据:

I did not have to do this on another grid in my application because it was configured to use data retrieved via another AJAX call, instead of data retrieved directly by the grid:

editurl: "clientArray"
datatype: "local"

相关文章