Skip to content
Niko Table

Row Context Menu Table

One row menu that powers both the "..." dropdown and the right-click context menu.

Gives every row a right-click context menu that matches its “…” (kebab) actions. You define the actions once and they show in both places. Right-click a row or open the ⋯ menu: both run the same actions.

row-context-menu.tsx

Right-click a row, or use the ⋯ menu.

Name
Team
Status
Alex MorganThunderActive
Jordan LeePhoenixInjured
Sam RiveraDragonsActive
Casey KimWolvesActive

This is the composable, shadcn-style way to do row actions. Write the actions once as a small component. Then use that same component in the kebab cell and in the body’s context-menu slot. No copied item lists, and no (row) => ... render function at the call site.

Three pieces make it work:

  • DataTableRowContextMenuSlot: nest it inside a DataTableBody or DataTableVirtualizedBody.
    • It renders nothing itself.
    • The body finds it and adds a right-click menu to every row, wrapped in a scope that carries the row.
  • DataTableRowMenuScope: gives the nested pieces the current row and the surface ("dropdown" or "context").
    • The context-menu body sets this up for you.
    • For the kebab, you wrap it around your DropdownMenuContent children.
  • Polymorphic RowMenuItem / RowMenuSeparator / RowMenuSub / …: each renders as the dropdown piece or the context-menu piece, based on the surface it reads from context. Use them like DropdownMenuItems.

Read the row inside your menu component with useDataTableRow<T>(). The same element then works for every row.

// 1. Define the actions ONCE — reads its row from context.
function PlayerRowMenu({ onView, onRemove }: PlayerRowMenuProps) {
const player = useDataTableRow<Player>()
return (
<>
<RowMenuItem onClick={() => onView(player)}>View profile</RowMenuItem>
<RowMenuSeparator />
<RowMenuItem variant="destructive" onClick={() => onRemove(player)}>
Remove player
</RowMenuItem>
</>
)
}
const rowMenu = <PlayerRowMenu onView={onView} onRemove={onRemove} />
// 2. Kebab cell — same element, rendered as a dropdown.
<DropdownMenuContent align="end">
<DataTableRowMenuScope row={row.original} surface="dropdown">
{rowMenu}
</DataTableRowMenuScope>
</DropdownMenuContent>
// 3. Right-click — same element, rendered as a context menu.
<DataTableBody>
<DataTableRowContextMenuSlot>{rowMenu}</DataTableRowContextMenuSlot>
</DataTableBody>

To hide the menu for some rows (locked, read-only, and so on), pass an enabledFor function to the slot. Return false and that row gets no menu:

<DataTableRowContextMenuSlot enabledFor={(row) => !row.isLocked}>
{rowMenu}
</DataTableRowContextMenuSlot>

To turn the menu off for the whole table (for example, no manage permission), don’t render the slot.

The row menu ships with the DataTable core:

pnpm dlx shadcn@latest add @niko-table/data-table

First time using @niko-table? See the Installation Guide to set up the registry.