如何禁用 ag-grid 的右 click/context 菜单?

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

我正在使用 ag-grid 企业版,我想禁用上下文菜单或右键单击网格单元格,但我没有找到任何解决方案。

这是我的代码

<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>

[suppressContextMenu]="true" 会满足您的要求。

或者,如果您在组件中定义 getContextMenuItems,只需 return 函数中的空数组。

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

看看this plunk I've created

您还可以有条件地决定是否不希望任何特定列使用它或不使用参数 params

suppressContextMenu:true for gridOptions

会工作