我正在尝试删除扩展Ext.grid.panel的Viewport组件中的选定行。下面的示例允许我选择行,但是将其实例化为Grid.Panel而不是Viewport。是否可以使用扩展网格的viewPort选择特定行。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);
}
}]
});
答案 0 :(得分:0)
首先,为您的网格指定一个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);
}
}