Shadcn React Table

Search documentation

Search the docs

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 & copyRight-click a cell for actions; click-to-copy enabled.
GitHub
ID
Jan 2, 2023
0%
Jan 13, 2023
9%
Jan 24, 2023
18%
Feb 4, 2023
27%
Feb 15, 2023
36%
Feb 26, 2023
45%
Mar 9, 2023
54%
Mar 20, 2023
63%
Mar 31, 2023
72%
Apr 11, 2023
81%
$4,120,536
Rows per page
1–10 of 48

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
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
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
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 itemsYour own column-menu item next to the built-in ones.
GitHub
ID
AvaThompsonOwnerEngineeringactive22$45,000Jan 2, 2023
0%
LiamNguyenAdminMarketinginactive25$47,137Jan 13, 2023
9%
NoahSilvaEditorDesignpending28$49,274Jan 24, 2023
18%
EmmaCarterViewerSalesactive31$51,411Feb 4, 2023
27%
OliviaRossiOwnerSupportinactive34$53,548Feb 15, 2023
36%
WilliamWalkerAdminEngineeringpending37$55,685Feb 26, 2023
45%
SophiaPatelEditorMarketingactive40$57,822Mar 9, 2023
54%
JamesMullerViewerDesigninactive43$59,959Mar 20, 2023
63%
IsabellaParkOwnerSalespending46$62,096Mar 31, 2023
72%
LucasReyesAdminSupportactive49$64,233Apr 11, 2023
81%
$4,120,536
Rows per page
1–10 of 48