我正在尝试按两个不同的列对 jqgrid 中的列进行排序。例如,我有一个列“StoreName”,它的排序将由“d0_key”和“d0_tot_key”列(均为整数)决定。我知道 colmodel 中的 sorttype 可用于创建自定义排序,但我找不到同时考虑两列的算法。下面是数据的简单表示。
StoreName d0_key d0_tot_key
92nd Gessner 1 0
92nd Gessner 1 0
Total Sum 1 10
Total Avg 1 20
Annco 2 0
Annco 2 0
Total Sum 2 10
Total Avg 2 20
最佳答案
版本4.5.0 of the jqGrid added multi-sort support .你应该能够做这样的事情:
只需确保您已打开 multiSort
:
$('#gridId').jqGrid({
...
multiSort: true,
...
});
这将使您能够单击多个标题。如果您想以编程方式排序,这应该可行:
$('#gridId')
.jqGrid('sortGrid', 'd0_key', true, 'asc')
.jqGrid('sortGrid', 'd0_tot_key', true, 'asc');
列模型对象上还有您可能感兴趣的其他附加属性,例如 firstsortorder
("asc"
/"desc "
) 和 sortable
(true
/false
)。
此外,看起来 4.5.1 和 4.5.4 中有一些针对多重排序的错误修复,所以我会继续下载最新版本。
关于javascript - jqgrid:基于两列排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19824233/