Disabling Context Menu

Tags: #<Tag:0x00007fd2cfb2bc78>

How do I disable the context menu and prevent it from showing if the user right clicks on a column header or row header or on a selection of multiple cells? I only need the context menu to be displayed if the user right clicks on a single table cell that isn’t a row/column header.

Hi @ahussein

One of the approaches it to block the options via hidden option in the menu http://jsfiddle.net/handsoncode/npbs31d0/
where you compare instance.getSelectedRangeLast().from.row with instance.getSelectedRangeLast().to.row and instance.getSelectedRangeLast().from.col with instance.getSelectedRangeLast().to.col.

The second one is using the updateSettings > contextMenu: false in the afterSelectionEnd hook.

UPDATE:
You can also pass the e.stopImmediatePropagation() in beforeOnCellContextMenu and that might me the best and simplest way to fo it.

1 Like

Hey Aleksandra,

Both these methods work perfectly for me, thank you!

However, I have a question about using beforeOnCellContextMenu(Event, CellCoords).

CellCoords returns the row and column intersect of a single cell when right clicking on a single cell or when right clicking on an area of multi-selected cells. Is there a way to get the entire area cell coordinates when highlighting an area rather than just the single cell coordinate that CellCoords parameter provides?

Having the area cell coordinates would be helpful in disabling the context menu option if the user has highlighted multiple cells.

Thanks for all the help!
Alaa

Try running console.log(this.getSelectedLast()) in the beforeOnCellContextMenu, where this is an instance of Handsontable.

1 Like

Perfect, thanks!

You’re welcome. I keep my fingers crossed for the project.

1 Like