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

柔情痞子 提交于 2019-12-10 07:01: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.



来源:https://stackoverflow.com/questions/27945026/how-to-show-a-menu-in-a-grid-extjs-5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!