Docs Editing & actions Cell actions Cell actions
Cells can have a right-click menu. Turn on the built-in one with enableCellActions: true — it offers Copy (when click-to-copy is on) and Edit (when the cell is editable) — or decide per cell with enableCellActions: (cell) => boolean.
Cell actions & copy Right-click a cell for actions; click-to-copy enabled.
ID
First name Sort by First name ascending Last name Sort by Last name ascending Email Sort by Email ascending Role Sort by Role ascending Department Sort by Department ascending Status Sort by Status ascending Salary Sort by Salary ascending Start date Sort by Start date ascending Progress Sort by Progress ascending U-1000 Ava Thompson ava.thompson@example.com Owner Engineering active 22 $45,000 Jan 2, 2023 U-1001 Liam Nguyen liam.nguyen@example.com Admin Marketing inactive 25 $47,137 Jan 13, 2023 U-1002 Noah Silva noah.silva@example.com Editor Design pending 28 $49,274 Jan 24, 2023 U-1003 Emma Carter emma.carter@example.com Viewer Sales active 31 $51,411 Feb 4, 2023 U-1004 Olivia Rossi olivia.rossi@example.com Owner Support inactive 34 $53,548 Feb 15, 2023 U-1005 William Walker william.walker@example.com Admin Engineering pending 37 $55,685 Feb 26, 2023 U-1006 Sophia Patel sophia.patel@example.com Editor Marketing active 40 $57,822 Mar 9, 2023 U-1007 James Muller james.muller@example.com Viewer Design inactive 43 $59,959 Mar 20, 2023 U-1008 Isabella Park isabella.park@example.com Owner Sales pending 46 $62,096 Mar 31, 2023 U-1009 Lucas Reyes lucas.reyes@example.com Admin Support active 49 $64,233 Apr 11, 2023 $4,120,536
Your own items
renderCellActionMenuItems sets the menu's contents (and turns the menu on). It receives { cell, row, table, internalMenuItems, closeMenu }: place internalMenuItems where the built-in items should go, or leave it out to replace them, and call closeMenu() from anything that isn't a menu item.
tsx Copy
import { ContextMenuItem, ContextMenuSeparator } from "@/components/ui/context-menu"
const table = useDataTable({
data,
columns,
getRowId: (row) => row.id,
enableCellActions: true,
enableEditing: true,
renderCellActionMenuItems: ({ cell, internalMenuItems }) => (
<>
{internalMenuItems}
<ContextMenuSeparator />
<ContextMenuItem onSelect={() => search(String(cell.getValue()))}>
Search for this
</ContextMenuItem>
</>
),
})
return <DataTable table={table} />
Click to copy
Enable click-to-copy on every cell with enableClickToCopy: true, or scope it to a single column through its meta. Set it to "context-menu" to copy from the cell menu instead of on click, or pass (cell) => boolean | "context-menu" to decide per cell.
tsx Copy
const columns = [
{
accessorKey: "email",
header: "Email",
meta: { enableClickToCopy: true },
},
]
Column actions menu
renderColumnActionsMenuItems sets the contents of every column header's actions menu. It receives { column, table, internalMenuItems, closeMenu }: put internalMenuItems where the built-in sort / filter / hide / group / pin items should go, or leave it out to replace them.
tsx Copy
import {
DropdownMenuItem,
DropdownMenuSeparator,
} from "@/components/ui/dropdown-menu"
const table = useDataTable({
data,
columns,
getRowId: (row) => row.id,
renderColumnActionsMenuItems: ({ column, internalMenuItems }) => (
<>
{internalMenuItems}
<DropdownMenuSeparator />
<DropdownMenuItem onClick={() => exportColumn(column.id)}>
Export column
</DropdownMenuItem>
</>
),
})
Column menu items Your own column-menu item next to the built-in ones.
ID
First name Sort by First name ascending Last name Sort by Last name ascending Email Sort by Email ascending Role Sort by Role ascending Department Sort by Department ascending Status Sort by Status ascending Salary Sort by Salary ascending Start date Sort by Start date ascending Progress Sort by Progress ascending U-1000 Ava Thompson ava.thompson@example.com Owner Engineering active 22 $45,000 Jan 2, 2023 U-1001 Liam Nguyen liam.nguyen@example.com Admin Marketing inactive 25 $47,137 Jan 13, 2023 U-1002 Noah Silva noah.silva@example.com Editor Design pending 28 $49,274 Jan 24, 2023 U-1003 Emma Carter emma.carter@example.com Viewer Sales active 31 $51,411 Feb 4, 2023 U-1004 Olivia Rossi olivia.rossi@example.com Owner Support inactive 34 $53,548 Feb 15, 2023 U-1005 William Walker william.walker@example.com Admin Engineering pending 37 $55,685 Feb 26, 2023 U-1006 Sophia Patel sophia.patel@example.com Editor Marketing active 40 $57,822 Mar 9, 2023 U-1007 James Muller james.muller@example.com Viewer Design inactive 43 $59,959 Mar 20, 2023 U-1008 Isabella Park isabella.park@example.com Owner Sales pending 46 $62,096 Mar 31, 2023 U-1009 Lucas Reyes lucas.reyes@example.com Admin Support active 49 $64,233 Apr 11, 2023 $4,120,536