Skip to content
Browse documentation
DocsComponents

Table

Structured data with consistent alignment and optional selection.

ProjectStatus
Weekend notesActive
A new ideaDraft

Installation

Terminal
pnpm dlx shadcn@latest add https://react-toolbox.io/r/table.json

New here? Set up your project first. Styles, fonts, and required components are included.

Usage

Put TableHead and TableRow directly inside Table. Use selectable and onRowSelect for selection, and keep selected on each row in sync with your state.

Use the Code tab above for a complete example. The import follows your configured UI alias. See Theming to customize colors, spacing, and style slots.

State and callbacks

Table derives selection from each TableRow selected prop. Handle onRowSelect by updating those row props; it receives row indices, so preserve your own stable item identifiers when sorting or filtering data.

selectable adds selection controls; multiSelectable enables multiple selected rows. Set selectable={false} for a table with no selection interaction.

API reference

Generated from the installed TypeScript source. Defaults are the values declared by each function; a dash means no parameter default is declared. Forwarded props can use the receiving component’s default. Callback types show the exact arguments passed to your handler.

Table

PropertyTypeDefault
multiSelectablebooleanfalse
selectablebooleantrue
classNamesTableTheme

Classes for the component's rendered parts. Applied after legacy theme overrides.

—
themeDeprecated aliasTableTheme

Use classNames for style slots; use ThemeProvider for design tokens.

—

Callbacks

PropertyTypeDefault
onRowSelect(selectedIndices: number[]) => void—

Also inherits ComponentPropsWithRef<'table'>, except the omissions and overrides in its exported props type below. Use the supported native aria-*, data-*, event, and element attributes as appropriate.

Additional defaults on inherited props: className = ''.

Style slots

Pass a map of Tailwind classes to classNames. Available keys:

  • asc
  • checkboxCell
  • head
  • headCell
  • numeric
  • row
  • rowCell
  • selected
  • sortIcon
  • sorted
  • table

theme is the deprecated compatibility alias. When both are provided, classNames wins conflicting utilities within each slot. See Theming for tokens and override rules.

TableHead

PropertyTypeDefault
displaySelectbooleantrue
multiSelectableboolean—
selectableboolean—
selectedboolean—
classNamesTableTheme

Classes for the component's rendered parts. Applied after legacy theme overrides.

—
themeDeprecated aliasTableTheme

Use classNames for style slots; use ThemeProvider for design tokens.

—

Callbacks

PropertyTypeDefault
onSelect(checked: boolean, event: React.MouseEvent<HTMLInputElement>) => void—

Also inherits Omit<ComponentPropsWithRef<'tr'>, 'onSelect'>, except the omissions and overrides in its exported props type below. Use the supported native aria-*, data-*, event, and element attributes as appropriate.

Style slots

Pass a map of Tailwind classes to classNames. Available keys:

  • asc
  • checkboxCell
  • head
  • headCell
  • numeric
  • row
  • rowCell
  • selected
  • sortIcon
  • sorted
  • table

theme is the deprecated compatibility alias. When both are provided, classNames wins conflicting utilities within each slot. See Theming for tokens and override rules.

TableRow

PropertyTypeDefault
idxnumber0
selectableboolean—
selectedboolean—
classNamesTableTheme

Classes for the component's rendered parts. Applied after legacy theme overrides.

—
themeDeprecated aliasTableTheme

Use classNames for style slots; use ThemeProvider for design tokens.

—

Callbacks

PropertyTypeDefault
onSelect(index: number, selected: boolean) => void—

Also inherits Omit<ComponentPropsWithRef<'tr'>, 'onSelect'>, except the omissions and overrides in its exported props type below. Use the supported native aria-*, data-*, event, and element attributes as appropriate.

Style slots

Pass a map of Tailwind classes to classNames. Available keys:

  • asc
  • checkboxCell
  • head
  • headCell
  • numeric
  • row
  • rowCell
  • selected
  • sortIcon
  • sorted
  • table

theme is the deprecated compatibility alias. When both are provided, classNames wins conflicting utilities within each slot. See Theming for tokens and override rules.

TableCell

PropertyTypeDefault
columnnumber—
numericbooleanfalse
rownumber—
sorted'asc' | 'desc'—
tagName'td' | 'th''td'
classNamesTableTheme & { tableCell?: string }

Classes for the component's rendered parts. Applied after legacy theme overrides.

—
themeDeprecated aliasTableTheme & { tableCell?: string }

Use classNames for style slots; use ThemeProvider for design tokens.

—

Callbacks

PropertyTypeDefault
onClick(event: MouseEvent<HTMLTableCellElement>, column?: number, row?: number) => void—

Also inherits Omit<ComponentPropsWithRef<'th'>, 'onClick'>, except the omissions and overrides in its exported props type below. Use the supported native aria-*, data-*, event, and element attributes as appropriate.

Additional defaults on inherited props: className = ''.

Style slots

Pass a map of Tailwind classes to classNames. Available keys:

  • asc
  • checkboxCell
  • head
  • headCell
  • numeric
  • row
  • rowCell
  • selected
  • sortIcon
  • sorted
  • table
  • tableCell

theme is the deprecated compatibility alias. When both are provided, classNames wins conflicting utilities within each slot. See Theming for tokens and override rules.

Exported TypeScript types

Expand a type to inspect its full declaration, including generic constraints, union branches, callback arguments, ref handles, and inherited props. Import these types from @/components/ui/material/table.

TableProps
tsx
interface TableProps extends ComponentPropsWithRef<'table'> {
  multiSelectable?: boolean;
  onRowSelect?: (selectedIndices: number[]) => void;
  selectable?: boolean;
  /** Classes for the component's rendered parts. Applied after legacy theme overrides. */
  classNames?: TableTheme;
  /** @deprecated Use classNames for style slots; use ThemeProvider for design tokens. */
  theme?: TableTheme;
}
TableHeadProps
tsx
interface TableHeadProps extends Omit<ComponentPropsWithRef<'tr'>, 'onSelect'> {
  displaySelect?: boolean;
  multiSelectable?: boolean;
  onSelect?: CheckboxProps['onChange'];
  selectable?: boolean;
  selected?: boolean;
  /** Classes for the component's rendered parts. Applied after legacy theme overrides. */
  classNames?: TableTheme;
  /** @deprecated Use classNames for style slots; use ThemeProvider for design tokens. */
  theme?: TableTheme;
}
TableRowProps
tsx
interface TableRowProps extends Omit<ComponentPropsWithRef<'tr'>, 'onSelect'> {
  idx?: number;
  onSelect?: (index: number, selected: boolean) => void;
  selectable?: boolean;
  selected?: boolean;
  /** Classes for the component's rendered parts. Applied after legacy theme overrides. */
  classNames?: TableTheme;
  /** @deprecated Use classNames for style slots; use ThemeProvider for design tokens. */
  theme?: TableTheme;
}
TableCellProps
tsx
interface TableCellProps extends Omit<ComponentPropsWithRef<'th'>, 'onClick'> {
  column?: number;
  numeric?: boolean;
  onClick?: (event: MouseEvent<HTMLTableCellElement>, column?: number, row?: number) => void;
  row?: number;
  sorted?: 'asc' | 'desc';
  tagName?: 'td' | 'th';
  /** Classes for the component's rendered parts. Applied after legacy theme overrides. */
  classNames?: TableTheme & { tableCell?: string };
  /** @deprecated Use classNames for style slots; use ThemeProvider for design tokens. */
  theme?: TableTheme & { tableCell?: string };
}

Material guidelines

  • Use tables for comparable values organized into consistent columns. Left-align descriptive text and right-align numeric headers and values.
  • Keep row selection distinct from sorting or other actions. On narrow screens, contain horizontal scrolling inside the table instead of widening the page.

Material Design 1: Data tables