select 行 ExtJS6.2 视口扩展 grid.panel

select row ExtJS6.2 viewport extends grid.panel

我正在尝试删除我的视口组件中扩展 Ext.grid.panel 的 selected 行。下面的示例允许我 select 行,但它被实例化为 grid.Panel 而不是视口。是否可以 select 具有扩展 grid.Panel

视口的特定行

相似:https://fiddle.sencha.com/#view/editor&fiddle/2ech 我进行了各种尝试,但我认为我的问题是我无法抓住网格。

我的代码

var mainView = Ext.create('Ext.container.Viewport', {
//extends grid.panel
extend: 'Ext.grid.Panel',

items: [{
    //xtype is used to re-use components or classes
    xtype: 'grid',
    store: userStore,
    columns: [{
        text: 'Name',
        dataIndex: 'name',
        flex: 1
    }, {
        text: 'Email Address',
        dataIndex: 'email',
        flex: 2
    }, {
        text: 'Phone Number',
        dataIndex: 'phone',
        flex: 2
    }]

}, {
    xtype: 'button',
    text: 'NEW',
    height: 50,
    width: '33%',
    handler: function () {
        var win = Ext.create('innerWindow');
        win.show();
    }
}, {
    xtype: 'button',
    text: 'VIEW',
    height: 50,
    width: '33%',
    handler: function () {
        var win = Ext.create('innerWindow');
        win.show();
    }
}, {
    xtype: 'button',
    text: 'DELETE',
    height: 50,
    width: '33%',
    handler: function () {
        let selected = grid.getSelection();
        //want to delete selected row
        //var record = userStore.getAt(0);
        userStore.remove(selected);
    }
}]

});

首先,为您的网格指定一个 ID:

id: 'MyGrid'

现在您可以引用网格:

handler: function () {
        var grid = Ext.getCmp("MyGrid");
        var store = grid.getStore();
        var selection = grid.getView().getSelectionModel().getSelection()[0];
        if (selection) {
            store.remove(selection);
        } 
    }