How can I disable right click/context menu for ag-grid?
Asked Answered
J

2

8

I am using ag-grid enterprise version and I want to disable context menu or a right click on the grid cells but I did not found any solution.

Here is my code

<ag-grid-angular #agGrid style="width: 100%; height: 100%;" id="myGrid" 
[rowData]="rowData" class="ag-theme-balham" [columnDefs]="columnDefs" 
[enableRangeSelection]="true" (gridReady)="onGridReady($event)"></ag-grid- 
angular>

enter image description here

Jinni answered 10/12, 2018 at 13:35 Comment(0)
M
19
suppressContextMenu:true for gridOptions

Will work

Malvoisie answered 10/12, 2018 at 13:58 Comment(0)
K
4

[suppressContextMenu]="true" would do your ask.

Alternatively, if you are defining getContextMenuItems in your component, simply return empty array from the function.

this.getContextMenuItems = function getContextMenuItems(params) {
  return [];
};
<ag-grid-angular
    #agGrid
    .........
    [getContextMenuItems]="getContextMenuItems"   // provide the function here
    (gridReady)="onGridReady($event)"
    ></ag-grid-angular>

Have a look at this plunk I've created

You can also conditionally decide if you don't want it for any specific column or not using the arguments params.

Kutenai answered 10/12, 2018 at 13:45 Comment(4)
Thanks. But adding [suppressContextMenu]="true" looks a simple solutionJinni
I tried both suppressContextMenu = true and the above approach. And they are surprisingly not the same result. I'm trying to suppress Context Menu on 1 column specifically because it contains URL/links, so I implemented getContextMenu() and checked for only when user click on that particular column, to return [ ] or null. right click doesn't bring up the browser default menu to "open link in new tab." however the suppressContextMenu= true solution, it does achieve the right click bring up browser default. But All columns are effected in this case.Goffer
that's why I provided the answer for getContextMenuItems. Keeping [suppressContextMenu]="true" would suppress context menu for all the columnsKutenai
Empty array is working for me but showing error UserFunc is not a function what should I do. I have to context menu items for columns but as soon as pivot or change tab in aggrid. I have to hide.Earleneearley

© 2022 - 2024 — McMap. All rights reserved.