我找不到如何在带有复选框列的网格中正确打开上下文菜单。只要在复选框单元格上执行右键单击,就会切换复选框。这不是人们对上下文菜单的期望。
onAdminListCellContextMenu: function(tableview, td, cellIndex, record, tr, rowIndex, e, eOpts) {
e.stopEvent(); // this is where the right click should have been stopped from toggling the button underneath!?
var sample = Ext.getCmp('AdminListContextMenu') || new Admin.view.AdminListContextMenu;
sample.showAt(e.xy);
}
从我的网格面板中调用:
xtype: 'gridpanel',
flex: 1,
id: 'AdminList',
store: 'AdminStore',
columns: [{
xtype: 'gridcolumn',
dataIndex: 'user',
text: 'User',
editor: {xtype: 'textfield'}
},{
xtype: 'checkcolumn',
dataIndex: 'admins',
text: 'Grant admin rights'
}],
listeners: {
cellcontextmenu: {
fn: me.onAdminListCellContextMenu,
scope: me
}
}
答案 0 :(得分:0)
试试这个,让我知道结果。
xtype: 'gridpanel',
flex: 1,
id: 'AdminList',
store: 'AdminStore',
selModel: Ext.create('Ext.selection.CheckboxModel', {
selType: 'checkboxmodel',
mode: 'SIMPLE',
checkOnly: true,
allowDeselect: true,
ignoreRightMouseSelection: true
},
multiSelect: true,
columns: [{
xtype: 'gridcolumn',
dataIndex: 'user',
text: 'User',
editor: {xtype: 'textfield'}
},{
xtype: 'checkcolumn',
dataIndex: 'admins',
text: 'Grant admin rights'
}],
listeners: {
beforeitemmousedown: {
function(grid, record, item, index, e, eOpts) {
if (e.button == 0) {
allowSelection = true;
} else {
allowSelection = false;
return false;
}
}
},
cellcontextmenu: {
fn: me.onAdminListCellContextMenu,
scope: me
}
}
答案 1 :(得分:0)
Ext.define('Ext.override.CheckColumn',{
override:'Ext.grid.column.Check',
processEvent:function(type, view, cell, recordIndex, cellIndex, e, record, row) {
if(type == "mousedown" && e.button > 0) return; // prevent mousedown event if mouse button not the left button.
return this.callParent(arguments);
}
});
在ExtJS 6.0.1中测试,使用风险自负。