DataTables for local rows and Arc queries
DataTables in Cratis Components render local arrays or results from Cratis Arc queries as React tables. Use local rows when you manage loading yourself, a snapshot query for a result fetched on request, or an observable query to update the displayed rows through a subscription.
When to Use
Section titled “When to Use”Choose DataTableCore when you already have an array of rows and want the table to display, sort, filter, and select from that array. It does not run a query for you. It also fits when you run a query yourself and need a custom loading or failure layout rather than the query tables’ status rows; see Loading, empty, and failed queries. Start with Column Configuration to define the cells you want to show.
Use DataTableForQuery for a generated Arc snapshot query: each request returns a result rather than subscribing to later changes. The table runs the query and handles server-side pagination. Follow its guide to connect the query proxy and configure selection.
When the displayed rows should follow updates from an Arc observable query, use DataTableForObservableQuery. The table manages the subscription and server-side pagination, so you do not need to copy each incoming result into a local array yourself. Its guide shows the query binding and how updates affect row selection.
Both query-backed tables sort, filter, and search only the loaded page by default. Pagination alone does not make a search cover the whole result. For that, configure serverQuery and a query that applies filtering and search before paging; Server mode explains the contract.
Components
Section titled “Components”All three tables render rows through DataTableCore and use Column to describe the cells. ColumnFilterMenu supplies the filter popup, and TablePaginator supplies page navigation. Their standalone contracts are below if you are composing your own table layout.
DataTableCore accepts a status from DataTableStatus (Ready, Loading, Failed, or Unauthorized); it defaults to Ready. Import DataTableStatus from @cratis/components/DataTables. For a loading table with no rows, it renders a status row; with rows, it retains them and marks the table busy. Failed or unauthorized states render an alert row. Override the text with loadingMessage, failureMessage, and unauthorizedMessage or configure CratisComponentsProvider’s messages.dataTable.
When a search or column filter is active and no rows are shown, the table renders filteredEmptyMessage instead of emptyMessage. The default says only the loaded page was searched, or is neutral when rowProcessing is None because the server applies the search.
DataTableCore keeps its own sort, column filters, and search text unless you control them. Pass sort with onSortChange, filters with onFilter, and globalFilter with onGlobalFilterChange to own that state, for example to persist it or to send it to the server. sort={null} means not sorted; leaving a prop undefined lets the table keep that piece of state itself, and the change callbacks report every change either way. Import DataTableSort, DataTableSortDirection, and DataTableRowProcessing from @cratis/components/DataTables.
When your query has already filtered and sorted the rows on the server, set rowProcessing={DataTableRowProcessing.None} so the table renders them as given instead of processing them a second time. The default, DataTableRowProcessing.Loaded, filters and sorts the rows the table was given. The query-backed tables manage this state for you when you set serverQuery: they send sorting and the mapped filter and search arguments to the server, then render the returned rows without local processing. The query must apply those filter and search arguments itself; see Server mode.
Local rows with DataTableCore
Section titled “Local rows with DataTableCore”Pass the rows you already hold as data. emptyMessage is required, and dataKey names the property that identifies a row, so a selection survives when the row objects are replaced:
import { useState } from 'react';import { Column, DataTableCore } from '@cratis/components/DataTables';
interface Order { id: string; customer: string; total: number; overdue: boolean;}
export function OrderTable({ orders, onOpen }: { orders: Order[]; onOpen: (order: Order) => void }) { const [selected, setSelected] = useState<Order[]>([]);
return ( <DataTableCore<Order> data={orders} dataKey='id' emptyMessage='No orders yet.' selectionMode='multiple' selectedItems={selected} onSelectedItemsChange={setSelected} onRowClick={(event) => onOpen(event.data)} rowClassName={(order) => (order.overdue ? 'order-overdue' : '')} scrollable scrollHeight='24rem' > <Column field='customer' header='Customer' sortable /> <Column field='total' header='Total' sortable /> </DataTableCore> );}Here onOpen and the order-overdue class belong to your application. The table sorts and filters the rows it was given unless you set rowProcessing, as described above.
| Prop | Purpose |
|---|---|
data |
The rows to show. Required. |
emptyMessage |
Shown when there are no rows. Required. |
dataKey |
The row property used as identity. Set it to keep a selection across refreshed row objects. |
selectionMode |
'single' selects a row through activation and reports through selection / onSelectionChange; 'multiple' adds row checkboxes and a select-all checkbox and reports through selectedItems / onSelectedItemsChange. |
selectionAriaLabel, selectAllAriaLabel |
Accessible names for the row and select-all checkboxes. They fall back to messages.dataTable, then Select row and Select all rows. |
onRowClick |
Called with a DataTableRowClickEvent ({ data, index }, where index is the position on the loaded page) when a row is clicked or activated with the keyboard. |
rowClassName |
Returns an extra class name for a row. |
scrollable, scrollHeight |
Put the table in a scroll container. scrollHeight is its maximum height (default 100%). |
globalFilterFields, globalSearchPlaceholder, globalSearchAriaLabel |
The row fields the search box searches, and its placeholder and accessible name. |
className, style, pt |
A class and inline style for the table, and attributes for its stable parts. |
The status, message, filtering, sorting and rowProcessing props are described in Components above.
Mobile cards
Section titled “Mobile cards”Set mobileLayout='cards' to show each row as a labeled card when the viewport is narrower than 640 CSS pixels. At exactly 640 pixels and above, the semantic table remains. Without this prop the table stays a table at every width; mobileBreakpoint alone does not enable cards.
import { Column, DataTableCore } from '@cratis/components/DataTables';
const projects = [{ id: 'example-1', name: 'Example Project', details: { status: 'Ready' } }];
export function ExampleProjects() { return ( <DataTableCore data={projects} dataKey='id' emptyMessage='No projects.' mobileLayout='cards'> <Column field='name' header='Project' sortable /> <Column field='details.status' header='Status' /> </DataTableCore> );}On a narrow viewport this renders a list of cards with “Project” and “Status” labels, using the same Column.body templates and nested fields as the table. A missing field renders a blank value. Use mobileBreakpoint={768} alongside mobileLayout='cards' for a different exclusive threshold; nonfinite or nonpositive values fall back to 640. The breakpoint measures the viewport, not the width of a containing panel. Server rendering and browsers without matchMedia use the table; hydration then checks the viewport.
DataTableForQuery and DataTableForObservableQuery accept the same two props. Changing presentation does not reset sorting, filters, search, selection or pagination and does not rerun the query. Loaded-page processing stays loaded-page processing; serverQuery still sends those operations to the server before paging.
Sortable and filterable columns have controls above the cards. Multiple selection has one select-all checkbox and one checkbox per card, even without a selection-marker column. Single selection uses a radio control. Click or press Enter/Space on an interactive card to activate it; links, buttons and editable content inside its body remain independent. When switching layouts removes the focused row or selection control, focus follows the same keyed row/control if available, otherwise the table root. Search and paginator focus are left alone.
Card sorting announces the active direction with messages.dataTable.sortAscending and sortDescending on CratisComponentsProvider (defaults Ascending and Descending). Existing loading, failure, unauthorized and empty messages are also used outside table markup. Refetching keeps loaded cards visible and busy. The paginator remains unchanged, including its localized messages.
Use the card-specific pt slots cards, card, cardLabel, cardValue, cardControls and cardStatus. Their data-cratis-part names are cards, card, card-label, card-value, card-controls and card-status. pt.card can add classes, styles and event handlers; preventing the click or key event cancels built-in activation. Existing row, cell and header slots still target the desktop table. Column body styles/classes and rowClassName also apply to cards. Width, wrapping and body-template layout remain under your control; long values wrap by default.
Common Features
Section titled “Common Features”All three table components share:
- Single or multiple row selection, with row checkboxes and a select-all header in multiple mode (
selectionMode='multiple') - Global filtering
- Custom column templates
- Empty, loading, failure, and unauthorized state messages (set
DataTableCore.statuswhen rendering a locally managed query) - Keyboard selection: each row is a tab stop, and Enter or Space selects it; in multiple mode it toggles the row (on
DataTableCore, only whenselectionModeoronRowClickis set) - Cratis-owned semantic Column markers and stable table parts
Keep an application-owned or direct toolkit table when the surface requires grouping or row expansion. Components does not emulate those behaviors over one loaded page; server-side sorting is supported through serverQuery as described above.
ColumnFilterMenu
Section titled “ColumnFilterMenu”ColumnFilterMenu is the same Cratis-owned filter trigger and draft/apply popup that Column uses when filter is enabled. Most tables should configure filtering through Column; use the component directly only when composing a custom table header or another filtering surface.
import { useState } from 'react';import { ColumnFilterMenu, type DataTableFilterConstraint,} from '@cratis/components/DataTables';
export function TotalFilter() { const [constraint, setConstraint] = useState<DataTableFilterConstraint>();
return ( <ColumnFilterMenu field='total' dataType='numeric' constraint={constraint} onApply={setConstraint} onClear={() => setConstraint(undefined)} /> );}| Prop | Type | Description |
|---|---|---|
field |
string |
Effective field being filtered; also supplies default accessible labels. |
dataType |
'text' | 'numeric' | 'date' | 'boolean' |
Selects the built-in editor and match-mode family. Defaults to 'text'. |
placeholder |
string |
Placeholder for the built-in value editor. |
showMatchModes |
boolean |
Shows the match-mode selector. Defaults to true. |
filterOptions |
ColumnFilterOption[] |
Offers a known set of { label, value } choices in a dropdown instead of a typed value, and narrows the match modes to Equals and Not equals. Takes precedence over filterElement. |
filterElement |
ColumnFilterElement |
Replaces the built-in editor. Its options expose draft value/mode updates and apply/clear actions. |
labels |
Partial<ColumnFilterMenuLabels> |
Localizes trigger, editor, match mode, and action labels. Provider-level defaults are also honored. |
pt |
ColumnFilterMenuParts |
Stable part attributes for the trigger, popover, menu, editor, actions, and action buttons. |
constraint |
DataTableFilterConstraint |
Currently applied value and optional match mode. |
onApply |
(constraint: DataTableFilterConstraint) => void |
Receives the draft constraint when Apply is activated. |
onClear |
() => void |
Removes the field constraint. |
The popup keeps draft edits local until Apply is activated. Clear resets the draft value and calls onClear; Apply calls onApply. Neither action closes the popup automatically—it remains open until the user dismisses it or toggles the trigger. Built-in date, numeric, boolean, and text editors use the corresponding match modes; register custom matching behavior through the DataTables matcher APIs rather than relying on a renderer-specific registry.
TablePaginator
Section titled “TablePaginator”Use TablePaginator when a custom query/list composition needs the same first/previous/next/last navigation as the query-backed tables. Pages are always zero-based.
import { TablePaginator } from '@cratis/components/DataTables';
<TablePaginator page={1} pageCount={8} pageSize={10} totalItems={75} onPageChange={(page) => loadPage(page)}/>;| Prop | Type | Description |
|---|---|---|
page |
number |
Current zero-based page. |
pageCount |
number |
Total page count. Boundary controls disable on the first and last pages. |
onPageChange |
(page: number) => void |
Receives the requested zero-based page. The host owns loading and current-page state. |
totalItems |
number |
Total record count. Together with pageSize, enables the loaded range report. |
pageSize |
number |
Rows per page. Together with totalItems, enables the loaded range report. |
pageLinks |
boolean | { siblings?: number; boundaries?: number } |
Opt-in numbered page buttons with gaps; defaults to false. |
ariaLabels |
object |
Localizes navigation, control names, and numbered page names. |
className |
string |
Extra class on the paginator root. |
pt |
TablePaginatorParts |
Stable attributes for the root, reports, navigation buttons, numbered pages, and gaps. |
TablePaginator does not fetch data or change pages internally. Keep page, pageCount, and the optional range inputs synchronized with the query result supplied by the host.
Numbered page links
Section titled “Numbered page links”Set pageLinks to show page buttons between previous and next instead of the info report.
true includes one sibling on each side of the current page and one boundary page at each end.
An object changes those counts: pageLinks={{ siblings: 2, boundaries: 1 }}.
The current button has aria-current='page' and data-selected; clicking any page still requests
its zero-based index. First/last buttons and the loaded range remain unchanged.
The default window shows every page for counts up to seven. Longer ranges keep the selected window
and boundary pages, fill a gap of one page with its number, and show a non-interactive,
aria-hidden ellipsis for larger gaps. For custom window sizes the short-range threshold is
2 * boundaries + 2 * siblings + 3 pages.
This complete example hides the first/last controls and range through the existing parts:
import { useState } from 'react';import { TablePaginator } from '@cratis/components/DataTables';
export function NumberedPages() { const [page, setPage] = useState(5); return ( <TablePaginator page={page} pageCount={12} pageLinks onPageChange={setPage} ariaLabels={{ page: (number) => `Página ${number}`, pages: 'Páginas' }} pt={{ first: { root: { style: { display: 'none' } } }, last: { root: { style: { display: 'none' } } }, range: { style: { display: 'none' } }, }} /> );}Use the same pageLinks prop on DataPage, DataTableForQuery, or
DataTableForObservableQuery. Their paginatorAriaLabels and paginatorPt props forward
labels and part attributes to the paginator.
| Part | Attributes apply to | State |
|---|---|---|
pages |
Numbered-page group container (HTMLAttributes<HTMLDivElement>) |
role='group' and the resolved group label |
page |
Each native numbered button (ButtonHTMLAttributes<HTMLButtonElement>) |
aria-current='page' and data-selected only on the current button |
ellipsis |
Non-interactive gap span (HTMLAttributes<HTMLSpanElement>) |
aria-hidden='true' |
Part names are exposed as data-cratis-part values. pt.page is a native button attribute
object, unlike the nested ButtonParts used by pt.first, pt.previous, pt.next, and pt.last.
Use pt.page.className, or [data-cratis-part='page'][data-selected], to customize the current page.
Accessible names resolve from ariaLabels first, then CratisComponentsProvider’s
messages.paginator, then English defaults. The new page: (number: number) => string
message receives the one-based number and defaults to Page ${number}. The optional pages
message names the group and defaults to Pages. Existing messages (navigation, first,
previous, next, last) keep their precedence.
The visible range text (1–10 of 32 by default) is also localizable through an optional
range: (start: number, end: number, total: number) => string message, set on ariaLabels or
messages.paginator. It receives the one-based start, the end clamped to the total, and the total:
<CratisComponentsProvider value={{ messages: { paginator: { range: (start, end, total) => `${start} a ${end} de ${total}` } } }}> <TablePaginator page={0} pageCount={4} pageSize={10} totalItems={32} onPageChange={setPage} /></CratisComponentsProvider>For a custom composition, import the pure paginatorPages(page, pageCount, siblings = 1, boundaries = 1) helper and its PaginatorPageItem type from @cratis/components/DataTables.
It returns ordered { kind: 'page', page: number } items with zero-based indices and
{ kind: 'ellipsis', key: 'start' | 'end' } gaps. A zero, negative, or non-finite count returns
no items; it clamps the current page to the available pages and truncates numeric inputs.
Negative window sizes become zero; non-finite window sizes use their defaults.
See Also
Section titled “See Also”- Choosing a component - Local, query-backed, and advanced table boundaries
- DataTableForQuery - Standard query tables
- DataTableForObservableQuery - Real-time tables
- Column Configuration - Customizing columns