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?
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 .
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.
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.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With