DataTable
Convenience wrapper around Table. Pass columns + data arrays and get header rendering, in-memory sort, and client-side pagination for free.
At a glance
- Pass
columns(header + cell renderer per column) anddata(array of objects) — DataTable handles the rest. - In-memory, client-side sort on any column marked
sortable: true. Click a header once for ascending, again for descending, a third time to clear. - Client-side pagination via the existing
usePaginationhook. Controls appear automatically whendata.length > pageSize. - Empty state shown automatically when
datais empty; override text or render any node viaemptyState. - Row press handler via
onRowPress. - Inherits all cosmetic props from
Table:striped,compact,bordered. - For full control over markup and layout, use the lower-level Table primitive directly.
Basic usage
With sort
Any column with sortable: true gets a clickable header with a direction indicator (↑ / ↓). Clicking a third time clears the sort and restores the original data order.
Pass defaultSort to pre-sort on mount:
With pagination
DataTable paginates automatically when data.length > pageSize. The default page size is 10. Pass a different value to pageSize:
The ‹ Prev / page / Next › controls appear below the table only when there is more than one page.
Empty state
When data is empty DataTable shows "No data" centered below the header row. Override with any string or node:
Custom cell rendering
cell receives the full row and can return any ReactNode:
Row press
Accessibility
- Column headers render as
<th>elements via the underlyingTable.HeaderCell. Screen readers associate data cells with their headers automatically. - Sortable headers include an
aria-label="Sort by <id>"on the interactive span. - Pagination controls use
aria-labelon Prev/Next andaria-live="polite"on the page indicator. - The empty-state cell spans all columns via
colSpanso it reads as a single region.
Deferred to v2
The following features are explicitly out of scope for v1 and are documented here so you know what to build around:
| Feature | Notes |
|---|---|
| Server-side sorting/pagination | Add onSort / onPaginate callbacks; DataTable becomes uncontrolled for these. |
| Filtering | Column-level filter inputs or a global search box. |
| Row selection | Checkbox column + selectedRows / onSelectionChange props. |
| Expanding rows | Sub-row renderer via expandedRow column. |
| Column resizing | Drag handle on HeaderCell. |
| Sticky headers | stickyHeader prop on Table; requires overflow: auto container. |
| Variable-width columns on native | width / minWidth on Column; v1 uses equal flex. |
API
Column<T>
DataTable
| Prop | Type | Default | Description |
|---|---|---|---|
data | T[] | — | Row data array. |
columns | Column<T>[] | — | Column definitions. |
pageSize | number | 10 | Rows per page. |
defaultSort | { id: string; direction: 'asc' | 'desc' } | — | Initial sort state. |
onRowPress | (row: T) => void | — | Row press/click handler. |
emptyState | ReactNode | "No data" | Shown when data is empty. |
striped | boolean | false | Inherited from Table. |
compact | boolean | false | Inherited from Table. |
bordered | boolean | false | Inherited from Table. |
className | string | — | Web only: extra classes on the table. |
testID | string | — | Test identifier. |