How to create a context menu for an extjs panel

I have a context menu like

var ctxMenu = Ext.create('Ext.menu.Menu', {
    items: [{ text: 'Edit', action: 'edit'}]
});

how can i add this to extjs panel? I do not see a suitable event in the panel, for example itemcontextmenuin a treepanel?

Thank you.

+3
source share
1 answer

In Ext.tree.Panelthere are events itemcontextmenuand containercontextmenu.

Update: The same events exist for Ext.grid.Panel. You probably want to subscribe to them and do something like this:

showContextMenu: function(e) {
    var me = this;

    if (me.contextMenu === undefined)
        return;

    e.stopEvent();
    me.contextMenu.showAt(e.getXY());
},

// Show context menu from the grid
gridContextMenu: function(view, rec, node, index, e) {
    this.showContextMenu(e);
},

// Show context menu from the empty area below grid records
containerContextMenu: function(view, e) {
    this.showContextMenu(e);
},
+4
source

All Articles