1

我正在使用 ExtJS6.2 我有一个简单的 Ext.grid.Panel

this.selModel = Ext.create('Ext.selection.CheckboxModel', {
        checkOnly: true,
        injectCheckbox: 1
    });

我需要网格中的数据以与网格中显示的数据相同的顺序。

如果我选择网格的所有项目,这工作正常。

selection = grid.getView().getSelectionModel().getSelection();

然后我取消选择网格中的一项 - 单击复选框

那么选择的顺序是不是搞混了呢?我怎样才能再次获得正确的订单?

提前致谢

4

1 回答 1

0

您可以使用以下覆盖来实现此行为:

Ext.define('Ext.selection.ModelOverride', {
    override: 'Ext.selection.Model',
    syncSortSelectedWithStore: false,
    getSelection: function () {
        if (this.syncSortSelectedWithStore && this.view && !Ext.isEmpty(this.view.getStore())) {
            var map = this.view.getStore().getRange().reduce((acc, cur, i) => {
                acc[cur.id] = i;
                return acc;
            }, {})
            this.selected.sort(function (a, b) {
                return map[a.id] - map[b.id];
            })
        }
        return this.callParent(arguments);

    }
});

同样在我的小提琴中,您可以查看示例,在控制台中我详细描述了它是如何工作的

于 2020-04-09T18:44:56.353 回答