Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How i can create context menu for extjs panel

Tags:

extjs4

i have context menu like

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

how i can add this to extjs panel? I am not seeing any suitable event in panel, like itemcontextmenu in treepanel?

Advance Thanks.

like image 437
Jom Avatar asked Dec 03 '25 19:12

Jom


2 Answers

There are itemcontextmenu and containercontextmenu events in Ext.tree.Panel.

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

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);
},
like image 143
sha Avatar answered Dec 06 '25 05:12

sha


This works for me on Sencha ExtJS 7.4 on a Ext.panel.Panel:

listeners: {
    el: {
        contextmenu: function(e) {
            e.preventDefault();
            let contextMenu = new Ext.menu.Menu({
                items: [{
                    text: 'Cut',
                    iconCls: 'cut',
                    handler: 'onCut'
                },{
                    text: 'Delete',
                    iconCls: 'delete',
                    handler: 'onDelete'
                }]
            });
            contextMenu.showBy(Ext.getCmp(blockId+'-panel'));
        }
    }
}
like image 44
Russell Lewandowski Avatar answered Dec 06 '25 05:12

Russell Lewandowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!