如何在 MUI 数据网格中仅隐藏一列的选项菜单?

Nor*_*mal 4 reactjs material-ui

我正在使用 MUI x(社区版本),我想隐藏特定列的选项菜单,而不是所有列。我仍然希望其他人显示此菜单,但仅对于此列,我想隐藏它。如何?

disableColumnMenu对所有列禁用它。

// const columns = [ ... etc, then eventually
{ field: 'actionMenu', headerName: strings.actions, sortable: false, filterable: false },
// ]
Run Code Online (Sandbox Code Playgroud)
<DataGrid
  disableSelectionOnClick
  rows={rows}
  columns={columns}
  density="compact"
  loading={isLoading}
  components={{ Toolbar: GridToolbar }}
  localeText={{
    noRowsLabel: strings.noModerators,
  }}
/>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Aki*_*kis 6

你们非常接近。

在您想要隐藏菜单的字段中尝试此操作

{ 
  field: 'actionMenu', 
  headerName: strings.actions, 
  sortable: false, 
  filterable: false, 
  disableColumnMenu: true // This will hide it only for the Actions column
},
Run Code Online (Sandbox Code Playgroud)

另外请看看这个工作代码和框,我仅隐藏“年龄”列的菜单,其余的则在悬停时显示菜单