Data Grid - Column menu
Customize your columns menu.
Column menu
Each column header comes with a column menu with quickly accessible Data Grid features like column visibility, sorting, filtering, and others.
It can be accessed by clicking on the 3-dots icon that appears on hover on a header cell or when focusing on a column header and pressing Ctrl+Enter (or ⌘ Command+Enter on macOS).
Customize column menu items
You can customize the column menu items by passing the slots
and slotProps
props to the <GridColumnMenu />
component:
slots
- use this prop to override default column menu slots or add new slots.slotProps
- use this prop to override or passdisplayOrder
for column menu items. You can also use this to pass extra props to custom column menu slots.
Adding a menu item
To add a new menu item, create a new item slot and pass it to the slots
prop. In the example below, the new slot is called columnMenuUserItem
but you can choose any name and it'll be added to the menu automatically.
You can also set the displayOrder
(default 100
) or pass new props to the slots using the slotProps
prop.
function CustomColumnMenu(props: GridColumnMenuProps) {
return (
<GridColumnMenu
{...props}
slots={{
// Add new item
columnMenuUserItem: CustomUserItem,
}}
slotProps={{
columnMenuUserItem: {
// set `displayOrder` for the new item
displayOrder: 15,
// Additional props
myCustomValue: 'Do custom action',
myCustomHandler: () => alert('Custom handler fired'),
},
}}
/>
);
}
Overriding default menu items
Use the slots
prop to override default menu items.
Check this table to know the overridable slot name for each menu item.
function CustomColumnMenu(props: GridColumnMenuProps) {
return (
<GridColumnMenu
{...props}
slots={{
// Override `columnMenuFilterItem` component
columnMenuFilterItem: CustomFilterItem,
}}
/>
);
}
Hiding a menu item
To hide a menu item, you can set its respective slot in slots
to null
.
Check this table to know the slot name for each menu item.
function CustomColumnMenu(props: GridColumnMenuProps) {
return (
<GridColumnMenu
{...props}
slots={{
// Hide `columnMenuColumnsItem`
columnMenuColumnsItem: null,
}}
/>
);
}
Reordering menu items
Every item is assigned a displayOrder
based on which it is shown before or after other items. It works in ascending order; the smaller the number is, the earlier it is displayed on the list. For new items default value for displayOrder
is 100.
You can override displayOrder
for the default or new items in slotProps
.
Check this table to see default displayOrder
for each menu item.
function CustomColumnMenu(props: GridColumnMenuProps) {
return (
<GridColumnMenu
{...props}
slotProps={{
// Swap positions of filter and sort items
columnMenuFilterItem: {
displayOrder: 0, // Previously `10`
},
columnMenuSortItem: {
displayOrder: 10, // Previously `0`
},
}}
/>
);
}
Default column menu items
As a reference, here are the column menu slots
along with the default item components and displayOrder
.
Custom menu component
You can also customize and replace the column menu by passing a fully custom component to the columnMenu
slot of the Data Grid. If you want to add some of the default menu items to your custom component, you can import and re-use them.
Disable column menu
By default, each column header has the column menu enabled. To disable the column menu, set the prop disableColumnMenu={true}
.
Column menu with Pro/Premium features
In the following demo, in addition to Data Grid MIT features, you can see commercial features like grouping, and aggregation in action. Try tweaking the values from respective column menu items.