DataTable

A data table component with sorting, selection, and pagination.

Installation

bash
npx @smicolon/cli add data-table

Run init once per project before adding components. See Installation.

Preview

NameEmailRole
Layla Haddadlayla@example.comAdmin
Omar Khalilomar@example.comEditor
Sara Nassersara@example.comViewer

Pagination

Loading State

NameEmailRole

Empty State

NameEmailRole

No users found

Props

PropTypeDefaultDescription
dataT[]—Rows to display.
columnsColumn<T>[]—Column definitions; each align is start, center or end of the reading direction.
getRowKey(row) => string | number—Unique key for each row.
loadingbooleanfalseShows the loading state.
emptyStateReactNode—Shown when there are no rows.
onRowClick(row) => void—Called when a row is clicked.
selectedKeystring | number—Key of the selected row.
stickyHeaderbooleanfalseKeeps the header visible on scroll.
Pagination{ page, totalPages, onPageChange, labels }—Pages through rows; labels translates its text.
classNamestring—Extra classes for the component.

Usage

tsx
import { DataTable, Column } from "@/components/blocks/data-table"

const columns: Column<User>[] = [
  { id: "name", header: "Name", cell: (row) => row.name },
  { id: "email", header: "Email", cell: (row) => row.email },
]

<DataTable
  data={users}
  columns={columns}
  getRowKey={(row) => row.id}
  onRowClick={(row) => console.log(row)}
/>