Display
DataTable
Table with global search, column sorting, pagination and a column visibility toggle, built on TanStack Table.
DataTable lives in its own entry point so that TanStack Table stays out of bundles that do not need it. Install the optional peer first.
bun add @tanstack/svelte-tablenpm i @tanstack/svelte-tablepnpm add @tanstack/svelte-table<script lang="ts">
import { DataTable, createCaColumnHelper } from "@codeatlasdev/ui/table";
const col = createCaColumnHelper<User>();
const columns = col.columns([
col.accessor("name", { header: "Name", meta: { label: "Name" } }),
]);
</script>
<DataTable {columns} data={users} />
There are two modes. In simple mode you pass columns and data and the table searches, sorts and paginates locally. In controlled mode you pass globalFilter, pagination and sorting together with their change handlers, and feed it one page of data plus total, which is what you want for server-side data.
Simple mode
Pass `columns` and `data`. Search, sort and pagination are managed automatically.
| ID | Name | Role | Status | |
|---|---|---|---|---|
| 1 | Ana Souza | ana@example.com | Admin | active |
| 2 | Bruno Lima | bruno@example.com | Developer | active |
| 3 | Carla Mendes | carla@example.com | Designer | inactive |
| 4 | Diego Ferreira | diego@example.com | Developer | active |
| 5 | Elena Castro | elena@example.com | Manager | pending |
| 6 | Felipe Rocha | felipe@example.com | Developer | active |
| 7 | Gabriela Nunes | gabi@example.com | Designer | active |
| 8 | Henrique Lopes | henrique@example.com | Admin | inactive |
| 9 | Isabela Torres | isa@example.com | Developer | active |
| 10 | Joao Almeida | joao@example.com | Manager | pending |
Rows
1 / 2
·
12
Code
Controlled mode
Own the state to drive server-side filtering, sorting and pagination.
| ID | Name | Role | Status | |
|---|---|---|---|---|
| 1 | Ana Souza | ana@example.com | Admin | active |
| 2 | Bruno Lima | bruno@example.com | Developer | active |
| 3 | Carla Mendes | carla@example.com | Designer | inactive |
| 4 | Diego Ferreira | diego@example.com | Developer | active |
| 5 | Elena Castro | elena@example.com | Manager | pending |
Rows
1 / 3
·
12
Code
Props
| Prop | Type | Default | Description |
|---|---|---|---|
columns | ColumnDef[] | – | Column definitions created with `createCaColumnHelper`. Required. |
data | TData[] | – | Row data. In simple mode pass all rows; in controlled mode pass the current page. Required. |
total | number | data.length | Total row count after filtering, used to compute the page count. Ignored in simple mode. |
globalFilter | string | undefined | Search value. Passing it switches the table to controlled mode. |
onGlobalFilterChange | (v: string) => void | undefined | Called when the user types in the search box. |
pagination | PaginationState | undefined | Controlled `{ pageIndex, pageSize }`. |
onPaginationChange | (v: Updater<PaginationState>) => void | undefined | Called when the page or page size changes. |
sorting | SortingState | undefined | Controlled sorting, `[{ id, desc }]`. |
onSortingChange | (v: Updater<SortingState>) => void | undefined | Called when the user clicks a column header. |
labels | { noResults?, noResultsSub?, clearSearch? } | undefined | Overrides the strings of the no-results state. |
searchPlaceholder | string | undefined | Placeholder of the search input. |
isLoading | boolean | undefined | Shows a loading indicator in the toolbar. |
isExporting | boolean | undefined | Shows the export button as busy. |
onExport | () => void | undefined | Enables the export button in the toolbar. |
onRowClick | (row: TData) => void | undefined | Called when a row is clicked. |
hasActiveFilters | boolean | undefined | Treats the table as filtered, which suppresses the empty state. |
emptyState | Snippet | undefined | Custom content shown when there is no data and no active filter. |
children | Snippet | undefined | Filter chips such as `DataTableFacetedFilter`, rendered in the toolbar. |
class | string | '' | Extra class names on the wrapper. |