Haedong
046

Data Table

Data
ButtonAction1
CalendarDate3
CommandNavigation1
DialogOverlay1
FieldForm1

selected: —

Customize

Select
Paging

Code

<DataTable
  columns={[
    { key: "name", header: "Name", sortable: true },
    { key: "meta", header: "Category", sortable: true },
    { key: "files", header: "Files", sortable: true, align: "right" },
  ]}
  rows={rows}
  selectable
  onSelectedChange={setSelected}
  pageSize={5}
  defaultSort={{ key: "name", direction: "asc" }}
/>

Install

npx shadcn@latest add https://components.haedong.dev/r/data-table.json

Props

Extends the native table props. Data-driven: columns describe header, cell (render), sort value and alignment; rows are your records with an id (or getRowId). Sortable headers are buttons with aria-sort on the th and cycle none → ^ → v → none. Selection is a Checkbox column lifted as ids; select-all is indeterminate for a part. pageSize puts a Pagination under the table.

PropTypeDescription
columnsDataTableColumn<T>[]{ key, header, render?, sortValue?, sortable?, align?, className? }
rowsT[]Records. getRowId(row) defaults to row.id.
sort / defaultSort{ key, direction } | nullControlled / uncontrolled sort; onSortChange on each cycle.
selectablebooleanAdds the Checkbox column. selected / defaultSelected / onSelectedChange lift the ids.
pageSizenumberRows per page; omit to show all.
emptyMessageReactNodeOne muted row when there are no rows. Defaults to "No rows".