【问题标题】:Do not change CheckColumn value on rightclick右键单击时不要更改检查列值
【发布时间】:2014-01-21 02:26:37
【问题描述】:

我找不到如何在带有复选框列的网格中正确打开上下文菜单。每当在复选框单元格上执行右键单击时,都会切换复选框。这不是上下文菜单所期望的。

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
    }
}

【问题讨论】:

    标签: extjs


    【解决方案1】:

    试试这个,让我知道结果。

    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
       }
    }
    

    【讨论】:

    • 感谢您的尝试,但我没有看到任何行为差异。即使在 beforeitemmousedown 函数中添加 window.alert(true); 也没有改变任何东西,因此不会触发此事件。
    • 我刚刚尝试了 BeforeCellContextMenu 事件 - 效果现在 Checkbox 仍处于切换状态,但我的上下文菜单不再打开。
    • 啊,顺便说一句,你的函数中的 window.alert 不会导致窗口弹出,值得第二次提及吗?
    • upps,然后在网格侦听器范围之外尝试此功能。原因是,看看会发生什么。通过Ext.getCmp('AdminList').on...获取网格
    • 亲爱的 Alex,我会试试 ExtJS fiddle,让我等一会儿。
    【解决方案2】:
    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 中测试,使用风险自负。

    【讨论】:

      猜你喜欢
      • 2013-09-17
      • 1970-01-01
      • 2012-05-29
      • 1970-01-01
      • 2013-06-18
      • 1970-01-01
      • 2017-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多