Skip to content

DataTable

Feature-rich data table with sorting, filtering, pagination, and selection.

Props

DataTableProps<T>

PropTypeRequiredDescription
dataT[]YesTable data
columnsColumnDef<T>[]YesColumn definitions
pageSizenumberNoRows per page (default: 10)
searchablebooleanNoEnable search
searchPlaceholderstringNoSearch input placeholder
searchColumnstringNoColumn to search
selectablebooleanNoEnable row selection
onSelectionChange(rows: T[]) => voidNoSelection change callback
exportablebooleanNoEnable CSV export
exportFilenamestringNoExport filename
loadingbooleanNoShow loading state
emptyMessagestringNoEmpty state message
classNamestringNoContainer class

Column Definition

ts
interface ColumnDef<T> {
  id: string
  header: string | ReactNode
  accessorKey?: keyof T
  accessorFn?: (row: T) => unknown
  cell?: (info: CellContext<T>) => ReactNode
  enableSorting?: boolean
  enableHiding?: boolean
}

Example

tsx
const columns: ColumnDef<User>[] = [
  { id: 'name', header: 'Name', accessorKey: 'name' },
  { id: 'email', header: 'Email', accessorKey: 'email' },
  {
    id: 'actions',
    header: 'Actions',
    cell: ({ row }) => <Button onClick={() => edit(row.original)}>Edit</Button>,
  },
]

<DataTable
  data={users}
  columns={columns}
  searchable
  selectable
  exportable
/>

See also