Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How i can create context menu for extjs grid

Tags:

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?

like image 390
edtsech Avatar asked Jul 19 '10 10:07

edtsech


People also ask

How to enable context menu in AG grid?

Default Context Menu If you want the grid to do nothing (and hence allow the browser to display its context menu) then hold down the Ctrl key while clicking for the context menu. If you always want the grid's context menu, even when Ctrl is pressed, then set allowContextMenuWithControlKey=true .

What is grid Extjs?

Grids are an excellent way of showing large amounts of tabular data on the client side. Essentially a supercharged <table> , Grid makes it easy to fetch, sort and filter large amounts of data. Grids are composed of two main pieces - a Ext. data. Store full of data and a set of columns to render.


2 Answers

Well, depending on what you want to do you can handle the following GridPanel events in the same manner as your example: contextmenu, cellcontextmenu, containercontextmenu, groupcontextmenu, headercontextmenu, rowbodycontextmenu or rowcontextmenu.

like image 41
Brian Moeskau Avatar answered Sep 20 '22 11:09

Brian Moeskau


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;
            }
        }
    }
});

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);
}
like image 63
Alan McCune Avatar answered Sep 22 '22 11:09

Alan McCune