如何向ext网格添加自定义排序

how to add custom sorting to ext grid

本文关键字:添加 自定义 排序 网格 ext      更新时间:2023-09-26

假设我有一个数据集:

[{ id: 1, name: "C" }, { id: 2, name: "A" }, { id: 3, name: "D" }]

当我为网格建立类似这样的列时:

this.columns = 
{
        id: {
            hidden: true
        }, 
        name: {
            text: 'Name',
            editor: {
                xtype: "textfield"
            }
        }
};

当我对'Name'列排序时,我希望它按'id'排序,而不是按字母顺序排序。

所以不像这样排序:A, C, D我希望它是:C, A, D

我已经尝试在名称列上使用dataIndex: 'id',然后将id映射到正确的名称以显示目的,但这会干扰我的编辑功能。

是否有一个简单的方法在Ext(我使用Ext 4.2)排序名称列的id ?

只需配置商店的sorters选项:

store: {
    ...
    sorters: [{property: 'id', direction: 'ASC'}]
}

sort方法