Guides
Column Actions Guide
How to use, customize, or disable column the action button and menu features of Shadcn Table
By default, Shadcn Table renders a column menu for each column header. A chevron button at the end of the header cell opens it, and so does a click on the header label. Every action in the menu can also be reached some other way (the sort editor, the filter chips, the view settings panel), so the menu is a shortcut that keeps the table's features close to the column they act on.
Example
Relevant Table Options
| Prop Name | Type | Description |
|---|---|---|
| enableColumnActions | boolean | |
| renderColumnActionsMenuItems | ({ closeMenu, column, internalColumnMenuItems, table }) => ReactNode[] | |
| stColumnActionsButtonProps | IconButtonProps | (({table, column}) => IconButtonProps); |
Relevant Column Options
| Column Option | Type | Description |
|---|---|---|
| enableColumnActions | boolean | Enable or disable column actions for this column. |
| renderColumnActionsMenuItems | ({ closeMenu, column, internalColumnMenuItems, table }) => ReactNode[] | |
| stColumnActionsButtonProps | IconButtonProps | ({ column, table }) => IconButtonProps |
Open the Column Menu
The chevron button at the end of each header cell (aria-label "Column Actions") and the header label are two triggers of the same menu. A second press on either one closes it. Clicking a header label does not sort the column: sorting is a deliberate action from the menu or from the sort editor. If you want a header that sorts on click, write a custom Header that calls column.getToggleSortingHandler().
A column with a custom Header render keeps its own content and events, so only the chevron opens its menu.
Default Menu Items
The menu lists only what applies to the column right now, in this order:
- Sort ascending, Sort descending, and Clear sort while the column is sorted. The direction the column is already sorted in is the one greyed item.
- Filter, and Clear filter while the column has a filter value. In the default chips mode, Filter opens the column's filter editor anchored to the header cell and adds its chip to the toolbar. See the Filter Chips Guide.
- Pin to start and Pin to end (each hidden while the column is already pinned on that side), Unpin while the column is pinned.
- Reset column size, only while the column's width differs from its default. Double-clicking the resize handle does the same.
- Group by, when grouping is enabled.
- Fixed position, a disabled item with a lock icon, for a locked column.
- Hide.
Items that do not apply are left out instead of greyed out. Sorting from the menu follows one rule: choosing a direction on a column that is already sorted replaces its direction, choosing a direction on another column adds it after the current sorts. "Show all columns" lives in the columns menu, not here.
Disable or Hide Column Actions Buttons
You can set the enableColumnActions table option to false in the table to disable this feature and hide the button in each column header completely. The header labels then stop opening a menu as well.
const table = useShadcnTable({
data,
columns,
enableColumnActions: false,
});
return <ShadcnTable table={table} />;Alternatively, if you only want to hide the column actions button in specific columns, you can set the enableColumnActions option for the desired column definition to false instead.
In this demo, we disable the column actions button for the 'ID' column.
Custom Column Actions Menu
If you do not like the default column actions menu items that Shadcn Table generates, you can provide your own custom menu items with the renderColumnActionsMenuItems table or column option. You can choose whether or not to include the internal menu items by using the internalColumnMenuItems parameter.
const table = useShadcnTable({
data,
columns,
renderColumnActionsMenuItems: ({ internalColumnMenuItems }) => {
return [
...internalColumnMenuItems, //optionally include the internal menu items above or below your custom menu items
<MenuItem key="custom-menu-item-1">Custom Menu Item 1</MenuItem>,
<MenuItem key="custom-menu-item-2">Custom Menu Item 2</MenuItem>,
];
},
});
return <ShadcnTable table={table} />;Open the Menu From Your Own Trigger
ST_ColumnActionMenu is exported, so you can open the same menu from an element of your own, for example in a custom Header. Pass the element as trigger; the menu opens when it is pressed and closes on a second press. Pass open and onOpenChange as well to control it. The same trigger prop works on ST_RowActionMenu, ST_ShowHideColumnsMenu and ST_FilterOptionMenu. The older anchorEl and setAnchorEl props still work for a menu without a trigger element.
import { Button } from '@/components/ui/button';
import { ST_ColumnActionMenu } from '@/components/ui/shadcn-table';
const columns = [
{
accessorKey: 'name',
header: 'Name',
enableColumnActions: false, //hide the built-in chevron, keep the custom one below
Header: ({ header }) => (
<ST_ColumnActionMenu
header={header}
trigger={<Button variant="ghost">Name</Button>}
/>
),
},
];Justify Column Actions Button
By default, the chevron sits at the end of the header cell, after the column label and the sort arrow. If you want to spread the header content differently, you can use a CSS selector in stTableHeadCellProps to change the justify-content property of the column header container.
View Extra Storybook Examples