如何解决ExtJS 7 如何在右键单击时选择网格行
我想打开上下文菜单并在 ExtJS 7 现代网格中选择右键单击的行。上下文菜单适用于以下代码。但是,我找不到选择行的方法。 grid.getSelectionModel()
在 ExtJS 7 中似乎不再可用。
// Listener in my Ext.app.ViewController manages to update and show context menu but not to select the row.
onContextMenu: function (e) {
const grid = this.getView();
const target = e.getTarget(grid.itemSelector);
if (target) {
e.stopEvent();
const item = Ext.getCmp(target.id);
if (item) {
// Would like to select row here with something like grid.getSelectionModel().selectRow(rowindex);
this.updateMenu(item.getRecord(),item.el,e);
}
}
}
解决方法
看看下面的小提琴示例(现代工具包 7.3.1)
Ext.application({
name: 'Fiddle',launch: function () {
const menu = new Ext.menu.Menu({
items: [{
text: 'Menu Item 1'
},{
text: 'Menu Item 2'
}]
});
Ext.Viewport.add({
xclass: 'Ext.grid.Grid',store: Ext.create('Ext.data.Store',{
fields: ['name','email','phone'],data: [{
name: 'Lisa',email: 'lisa@simpsons.com',phone: '555-111-1224'
},{
name: 'Bart',email: 'bart@simpsons.com',phone: '555-222-1234'
}]
}),columns: [{
text: 'Name',dataIndex: 'name',width: 200
},{
text: 'Email',dataIndex: 'email',width: 250
},{
text: 'Phone',dataIndex: 'phone',width: 120
}],listeners: {
childcontextmenu: function (grid,location) {
const {
record,event
} = location;
grid.deselectAll();
grid.setSelection(record);
menu.showAt(event.getX(),event.getY());
event.stopEvent()
}
}
})
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。