How to show a menu in a grid - ExtJS 5?

2019-05-07 07:25发布

问题:

I am trying to show a menu in a grid panel. I have a actioncolumn to display an icon and i want apply an effect... when the mouse is over that icon, a menu will be displayed.

How i can do this in extjs 5?

My actioncolumn is this:

{
    xtype: 'actioncolumn',
    width: 70,
    items: [{
    icon: 'resources/images/icons/cog_edit.png', // Use a URL in the icon config
            tooltip: 'Edit',
            handler: function(grid, rowIndex, colIndex, a, b, c) {

            }
    }]
}

回答1:

Referring to this post that I mentioned in the comments, your solution may look something like this:

var menu_grid = new Ext.menu.Menu({
   items: [
       { text: 'Add', handler: function() {console.log("Add");} },
       { text: 'Delete', handler: function() {console.log("Delete");} }
   ]
});

...
{
    xtype: 'actioncolumn',
    width: 70,
    items: [{
       icon: 'resources/images/icons/cog_edit.png', // Use a URL in the icon config
       tooltip: 'Edit',
       handler: function(grid, rowIndex, colIndex, item, e, record) {
           var position = e.getXY();
           e.stopEvent();
           menu_grid.showAt(position);
       }
    }]
}

EDIT: Be careful creating items like this, when they are hidden they are not removed completely and can cause memory leaks, refer to this post for further information and possible workarounds/solutions.



标签: Extjs menu grid