我如何创建extjs网格的上下文菜单 [英] How i can create context menu for extjs grid

查看:143
本文介绍了我如何创建extjs网格的上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以为树创建上下文菜单,并附加到contextmenu事件。
代码:

I can create context menu for tree and attach to 'contextmenu' event. Code:

contextMenu = new Ext.menu.Menu({
  items: [{
    text: 'Edit',
    iconCls: 'edit',
    handler: edit
  },...]
})

Ext.getCmp('tree-panel').on('contextmenu', function(node) {
  contextMenu.show(node.ui.getAnchor());
})

但是我可以如何为网格元素创建上下文菜单?

But how I can create context menu for grid elements?

推荐答案

首先定义您的上下文菜单

First define your context menu

mnuContext = new Ext.menu.Menu({
    items: [{
        id: 'do-something',
        text: 'Do something'
    }],
    listeners: {
        itemclick: function(item) {
            switch (item.id) {
                case 'do-something':
                    break;
            }
        }
    }
});

然后为所需的事件创建一个监听器。记住停止事件的默认行为非常重要,以便您可以用自己的行为替换它。如果不调用event.stopEvent()方法来阻止事件冒泡,那么浏览器的默认上下文菜单将会出现,而不管你做什么。

Then create a listener for the desired event. It is very important to remember to stop the event's default behaviour so you can replace it with your own. If you don't call the event.stopEvent() method to stop the event bubbling onwards then the brower's default context menu will appear regardless of what you do.

rowcontextmenu: function(grid, index, event){
     event.stopEvent();
     mnuContext.showAt(event.xy);
}

这篇关于我如何创建extjs网格的上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆