Reputation: 509
We use ag-grid and I need to control the way context menu items are being generated based on mouse and keyboard events. In this case I need to add an optional context menu item if alt+right click are pressed (rather than just right click). Simply binding event listeners on our end does not help because the context menu items are being bound before the event listener is being fired so I can't check if the user pressed them. Any advise will be appreciated.
Upvotes: 0
Views: 980
Reputation: 11598
As per documentation Configuring the Context Menu, you can provide context menu items using gridOptions.getContextMenuItems
function. Here you can find if Shift or Ctrl is pressed or not.
if(this.event.altKey === true) {
result.push({name: 'Alt key is pressed', disabled: true});
}
if(this.event.shiftKey === true) {
result.push({name: 'Shift key is pressed', disabled: true});
}
Have a look at this plunk I've created: Context Menu Example
Based on the key you press while doing mouse right click, one item is getting added to the context menu.
Upvotes: 1