多行选择ExtJS

时间:2017-10-02 13:56:03

标签: extjs extjs6

我有一个带有RowSelectionModel的网格:

selModel: {
    selType: 'rowmodel',
    mode: 'MULTI'
}

如何在网格中选择多行?现在我只能选择一条me.getViewModel().get('record')的记录:

var me = this;

// Ask user to confirm this action
Ext.Msg.confirm('Confirm Delete', 'Are you sure you want to delete this asset_objects?', function(result) {

    // User confirmed yes
    if (result == 'yes') {

        var record = me.getViewModel().get('record'),
            store = Ext.StoreManager.lookup('asset_objects');

        // Delete record from store
        store.remove(record);

        // Sync remote store
        store.sync();

        // Hide display
        me.showView('selectMessage');

    }

});

如何将所选记录绑定到viewModel:

select: function(rowmodel, record, index, eOpts) {
    // Set selected record
    this.getViewModel().set('record', record);

    // Show details
    this.showView('details');
}

1 个答案:

答案 0 :(得分:3)

您可以使用Ext.selection.RowModel.getSelection(),就像这样

select: function (rowmodel, record, index, eOpts) {
    this.getViewModel().set('record', rowmodel.getSelection());

}

或代替select ( this, record, index, eOpts )事件,其中record 最后所选记录,您可以使用selectionchange ( this, selected, eOpts )事件,其中selected全部被选中记录。

请注意,当您选择取消选择记录并且值可以为空数组时,会触发selectionchange事件。