DataTable handbook
v1.15.0 · @snowui-design-system/components
License: Before reading component documentation, source, or npm usage instructions for the first time, read the full LICENSE. Reuse that review for the same task and version. Public API configuration and internal implementation changes have different license implications. All components use the unified runtime package; source rights remain governed by the license.
Overview
Display and manage structured data with searching, sorting, selection, actions, pagination, and loading states.
When to use it
It is used when file or record lists need to be searched, filtered, sorted, pagined, checked or manipulated columns. DataTable coordinates the data status, and internally combines TableToolbar, Table series and Pagination; Table for pure display. The selection needs to be explicitly enabled, and the stable rowKey and rowId are used; the operation column is configured through actions. Business request functions and data formatting are provided by the page.
The client mode processes the data locally, and the server mode requests and provides results by the page; children receives the current rendering status.
Explicitly enable selection / actions; rowKey is indexed by default. When sorting or updating data, the stable business ID should be used, and TableRow.rowId should be consistent with it.
The page number starts from 1; the first loading, background refreshing and additional loadMore are in different states.
Quick start
This example shows the recommended basic composition. See the sections below for more cases and composition limits.
API
See the base component documentation for inherited capabilities not redeclared here. This table lists only named public Props declared by this component.
Usage boundaries and details
Pass column headings through TableHead’s children slot. Text, icons, and non-interactive components may be combined. Give icon-only headings an accessible name, and do not nest interactive controls in sortable headings. See TableHead icon and component headings.
Layout model
Main layout model: composite management layout.
Structure:
Root Frame (column status and combination shell)
TableToolbar of the user's combination (optional fixed operation area)
Table (semantic table area)
Pagination (optional paging area)
Other status areas such as loading / error / empty declared by the user
Local layout source: Root Frame uses column + contentFill to manage the direct area; TableToolbar maintains its own row slot host layout, Table maintains the native table layout, and Pagination maintains the inline shell layout. DataTable only coordinates regional arrangement and data status, and does not rewrite the main layout model of subcomponents.
Padding attribution: DataTable root layer does not create padding; toolbar, table Cell, paging and custom status areas are the responsibility of their respective components. The table header of the internal Table and the left and right padding of the data cell respond according to the width of the Table container between 4px and 12px, keep 8px up and down, the outer edge of the table is at least 8px, and the minimum between the adjacent column contents is 8px; DataTable does not copy the cell padding implementation.
Gap attribution: Root Frame uniformly controls the spacing of the direct area, which defaults to var(--gap-3)(12px); the internal gap of the subcomponent is controlled by the subcomponent itself.
Rolling attribution: DataTable does not build a separate rolling area, and the horizontal overflow directly inherits the local horizontal viewport and viewport bottom track of the internal Table; vertical virtualization or fixed table headers are still clearly provided by the upper business area. loadMoreMode="auto" Only observe the tail sentry inside DataTable: give priority to using the nearest vertical scrolling ancestor as root, and use the page viewport when it can't be found, and do not change the attribute of the vertical scrolling container.
When a columnId matches a row-object field, DataTable reads its original value and makes TableHead sortable. A date field may hold a Date object, numeric timestamp, or ISO 8601 date-time with zone; no sortType: "date" is needed. If sorters is supplied, its result provides the display value. A TableHead without a matching field or sorter stays static.
When defaultSort is not declared on any TableHead or DataTable, and the current sort === undefined, DataTable does not derive the ascending order of the first column, nor does it apply any other implicit sorting. The client mode directly retains the input order of rows prop; when the page enters filteredRows, it restores/maintains the original relative order of filteredRows.
TableHead defaultSort defines the default column and the default direction at the same time, which takes precedence over DataTable's own compatibility prop. When defaulting, the column is cycled according to "default → reverse → default", and only the reverse display activates the visual. When TableHead declares defaultSortActive at the same time, the default direction also displays the activation vision, and the loop is changed to "default → reverse → no sorting → default". Other columns remain "unsorted → ascending → descending → unsorted".
The correct way to write relative dates is formatDate(row.createdAt, { relative: true, now }). Sorting continues to compare row.createdAt, and will not compare Just now.
The default area spacing of DataTable's toolbar, Table and Pagination is 12px. striped uses Surface/3 as the odd line background from the first line, does not display the dividing line, and all data lines always maintain 12px outer rounded corners; the header of divided maintains a right angle with the two ends of the static data line, the lower line of the header is Black/20% 0.5px, the dividing line of the data line is Black/10% 0.5px, and there is no dividing line at the end line. In the dividing line mode, the beginning and end of the hover line form a 12px rounded corner, and the upper and lower adjacent dividing lines are hidden at the same time; when the mouse is moved out, the background exits immediately, and the background afterglow of the rounded corners is restored to the right angle is not displayed.
Responsive
DataTable shares Table’s complete responsive rules: move role columns into overlays, compress spacing, then scroll or hide ordinary columns from right to left. horizontalScroll defaults to true. With false, TableHead responsiveHide={false} protects a column and the first ordinary column always remains. Text in the final column may shrink and truncate with a Tooltip for the full value; fixed-size controls still trigger scrolling. Explicit Table settings take priority. DataTable adds no separate measuring or scrolling layer.
Selection column and operation column
Default read-only table: selection={false}, actions={false}, checkbox columns and operation columns are not displayed. In markup, you can still declare <TableHead as="selection" /> / <TableCell as="actions">, etc.; when DataTable is closed, the whole column is not rendered and does not participate in column registration.
Read-only default state skips row selection Set query and fully selected collection scanning at the same time; TableRow does not read the selected state and does not register rowId. After turning on selection, restore the complete selection path, and the DOM and interaction protocol remain unchanged.
actions={true} Keep the original explicit combination: the business can still write its own buttons in each <TableCell as="actions">. When passing the configuration object, the actions Cell of undeclared children uses OverflowActions by default; explicit children always replace the default content.
The default column width of the configuration mode is 160px; compact="auto", overflow="all", overflowFrom="end". resizable defaults false; only roleLayout="column" supports actions column dragging, and the overlay mode never provides column width Indicator. The drag results are taken over by Table's columnWidths.__actions and sent to each row in real time; each OverflowActions receives the value availableWidth, and no new size observer will be created for each Cell. The overlay mode uses the same actions width as the floating layer width.
When the More menu is expanded, the current responsive allocation is frozen, and the row hover hidden rule also treats the open SelectButton as visible to avoid the disappearance of the trigger after the column width or pointer leaves the row. Separator is only retained when there are still operations on both sides, and will not remain independently in the visible area or at the beginning and end of the menu.
Line preview
After configuring onRowPreview, DataTable provides TableRow with a row preview processor through Table Context. TableRow only triggers the processor in the blank area in the row; clicking on the link, button, input control, selection column or actions column control will not trigger the row preview. When onRowPreview is not configured, the blank click in the line does not respond; when selection={true}, the selection is still responsible for the selection role column.
Load Skeleton rows for the first time
When loading && rows.length === 0, DataTable provides the first loading semantics to the descendants TableBody through Table Context; TableBody retains the real TableHeader and automatically generates the same number of 40px Skeleton data rows as the current pageSize according to the registered TableHead column structure. The Skeleton line uses the real tr / td semantic structure but the whole aria-hidden, and the DataTable root continues to output aria-busy="true".
The number of skeleton rows directly follows the normalized
pageSize; the default ispageSize=10, so 10 lines are generated when the number of paged rows is not set.Do not provide independent Skeleton row attributes, avoid the high inconsistency between the loading state and the real paging data, and reduce the page jump when the first data appears as much as possible.
Skeleton only replaces the first empty data loading; if there are already rows at
loadingorrefreshing, continue to keep the existing data, and add the Spinner row in the middle of the column at the end of the TableBody to avoid the layout jumping when refreshing and clearly expressing that it is still loading.TableHeadregisters the column order, role and column width identification through the Table Context specified in the documents of both parties; DataTable / TableBody does not scan the subcomponent class name or internal DOM.TableBody loading={false}can explicitly close the Skeleton rows inherited from DataTable Context; the independent Table can be actively enabled by<TableBody loading>. At this time, the number of paging rows cannot be read and will be returned to 10 lines.
Action group configuration and visual budget
The actions configuration supports maxVisible (default 3), buttonProps, parts, and moreLabel using the corresponding OverflowActions types. Items support target, rel, buttonProps, and parts. The default is progressive overflow from the end; explicit all, compact, and direction settings remain supported. Group styles apply only to the generated group. Per-item buttonProps override that item's parts.Button. Explicit children replace the generated content; an explicit OverflowActions shares the table layout budget without inheriting generated-group visuals.
The action area uses the smallest of 20% of the table's visible viewport, 14rem, and the explicit or dragged column width, reserving space for selection and protected data. The budget includes padding, More, and the fade footprint. More keeps its minimum usable target size; very narrow tables scroll locally instead of shrinking text or controls or hiding data to retain actions.
DataTable style overlay
Read the full LICENSE first; reuse that review for the same task, version, and scope.
First use public component Props to match the desired appearance, preserving the existing look where possible. If changes are necessary, follow the style selection and override order: use your own class (including Tailwind already in the project) or an instance style. The names below are public overrides actually consumed by source; check their scope and do not modify private DOM. Choose the correct SnowUI token family. External apps need not install SnowUI website utilities.
This component source does not directly consume a registered component-specific override. Style composed children through public parts or an explicit child; do not guess variable names.
DataTable type and status
Required Props: no named required Props.
Bidirectional binding: bind:sort, bind:query, bind:filters, bind:page, bind:pageSize, bind:state, bind:selectedRowIds.
Inheritance statement: Omit<FrameProps, "children" | "variant">. The inheritance ability is subject to the public document of the base class; the fields in Omit have been excluded and cannot be used as they are according to the base class.
The following type declarations are actually referenced by public Props and come from source. A Svelte Snippet denotes a content fragment; ComponentProps denotes the Props of the corresponding component.
DataTableMode
Source: components/src/components/DataTable.svelte
Sorter
Source: components/src/components/DataTable.svelte
Searcher
Source: components/src/components/DataTable.svelte
Filterer
Source: components/src/components/DataTable.svelte
TableSortState
Source: components/src/lib/table-context.svelte.ts
TableSortDirection
Source: components/src/lib/table-context.svelte.ts
DataTableLoadMore
Source: components/src/components/DataTable.svelte
DataTableLoadMoreRequest
Source: components/src/components/DataTable.svelte
DataTableLoadMoreSource
Source: components/src/components/DataTable.svelte
DataTableLoadMoreMode
Source: components/src/components/DataTable.svelte
DataTableRenderState
Source: components/src/components/DataTable.svelte
DataTableVariant
Source: components/src/components/DataTable.svelte
DataTableActionsConfig
Source: components/src/components/DataTable.svelte
DataTableActionsItem
Source: components/src/components/DataTable.svelte
DataTableActionItem
Source: components/src/components/DataTable.svelte
OverflowActionsActionItem
Source: components/src/components/OverflowActions.svelte
OverflowActionIcon
Source: components/src/logic/overflow-actions.svelte.ts
GlobalButtonProps
Source: components/src/components/OverflowActions.svelte
ButtonProps
Source: components/src/components/OverflowActions.svelte
ControlledGlobalButtonKeys
Source: components/src/components/OverflowActions.svelte
DataTableActionSeparatorItem
Source: components/src/components/DataTable.svelte
TableRoleLayout
Source: components/src/lib/table-context.svelte.ts
TableRoleOverlayBlurMode
Source: components/src/lib/table-context.svelte.ts