Data Display

DataTable

Data-driven convenience wrapper over the compositional Table family that renders a full semantic table from columns and rows, with custom cells, day groups, a footer and rows that open a detail pane.

import { DataTable } from '@lostgradient/cinder';
tabledata
01

Overview

Reference usage

Data-driven accessible table that renders rows and columns into a real <table> with <caption>, scoped column and row headers, optional sortable columns, and a horizontal-scroll responsive container.

See the tabular family boundaries. DataTable is the native-table convenience layer; use Table for bespoke cell composition and DataGrid when cell focus, range selection, or grid semantics are required.

Usage

svelte
<script lang="ts">
  import { DataTable } from '@lostgradient/cinder';
  import type { DataTableColumn } from '@lostgradient/cinder';

  type Student = { name: string; score: number };

  const columns: DataTableColumn<Student>[] = [
    { key: 'name', label: 'Name', rowHeader: true },
    { key: 'score', label: 'Score', sortable: true, align: 'end' },
  ];
  const rows: Student[] = [
    { name: 'Ada', score: 98 },
    { name: 'Grace', score: 95 },
  ];
</script>

<DataTable {columns} {rows} caption="Class roster" />

Guidance

Set virtualized with a fixed rowHeight when the table is rendering thousands of same-height append-only rows. The virtualized path keeps the <table>, <thead>, and <tbody> semantics intact, sets aria-rowcount to the full logical row count, and annotates mounted body rows with full-table aria-rowindex values. Variable or measured body row heights are out of scope for this mode.

Use When

  • Rendering a roster, cohort, or assignment view from row/column data with real table semantics.
  • Needing sortable columns with screen-reader-announced sort state out of the box.

Avoid When

  • Composing a bespoke table layout with custom cell markup — use the compositional Table family directly.
  • Visualizing dense numeric magnitude across two dimensions — use matrix-chart instead.

Cells that hold controls

Pass a cell snippet to draw the content of every body cell, and mark the columns that hold controls with controls ('fit' for a checkbox or switch that keeps its size). The table then stacks on a narrow container: see Table. Pass rowMessage and hasRowMessage for a line that spans the full row under the row it belongs to, such as a failed save.

groupBy opens each run of rows with a header row that names the group and, after a dot, its detail (Today, Nov 2 · Central time). footer draws a row below the last, such as "Showing 12 of 1,240 events, newest first. Scroll to load more." onReachEnd fires when the end scrolls into view, so a long table loads more rows by scrolling and needs no Load more button.

Rows that open

Pass onRowOpen and openRowId to make each row open a detail pane. Rows take one tab stop, Arrow keys, Home and End move between them, Enter or Space opens, and the open row is highlighted and aria-current. Put the table in the list slot of ListDetail through its listBody.

Live preview

Audit log in a list and detail

Audit events
When
What
Target
Today, Nov 2 Central time
10:45 AMRemoved the Anthropic keyAnthropic provider
10:42 AMStarted a runChat › Refund order 4471
9:00 AMServer startedInterborough 2.4.1
Yesterday, Sun Nov 1 Central time
4:12 PMDeleted a chatScratch test

Nothing selected

Choose an item from the list to see it here.

02

When to use

Use when
  • Rendering a structured dataset where columns and rows are known at runtime (e.g. API responses, config-driven dashboards).
  • You want correct scope=col / scope=row semantics and aria-sort wiring without writing Table.Header / Table.Body manually.
Avoid when
  • You need nested components in header cells or column spanning — use the compositional Table family directly.
  • You need fully custom cell or row composition — use Table directly.
03

Examples

Audit log in a list and detail

A table in the list slot of ListDetail. Rows group by day under a header that names the zone, the open row stays highlighted beside its detail, and the footer counts the rows. More rows load as the end scrolls into view, with no Load more button.

Class roster

A class roster with a sortable grade column. The Name column is the row header (scope="row"). Bind sort state and reorder rows in a $derived expression.

Sortable data table

Multiple sortable columns with a scrollable wrapper. Sort state is bound and rows are reordered via $derived.

Virtualized data table

A semantic table that windows 10,000 fixed-height body rows while preserving full row counts and row indexes.

04

Props

Props for data-table
Name
Type
Default
Description
columns required DataTableColumn<Row>[] Column descriptors defining the headers and cell rendering for each column.
rows required Row[] Row data. Each entry is read via column.key for each column.
caption text Visual caption rendered as a <caption> element above the table.
sort bindable TableSort | undefined Bound sort state. When the user activates a sortable header cell, this prop is updated with the new { column, direction }. The consumer is responsible for reordering rows in response — DataTable does not sort internally. Pass undefined initially when no column is sorted; the component will never write back undefined itself (sort always toggles to a column).
selectable 'none' | 'single' | 'multiple' 'none' Enables checkbox-based row selection. "none" renders no selection controls, "single" allows one selected row id, and "multiple" allows any number. Selection state is exposed through row checkbox controls; native table rows do not emit aria-selected. Defaults to "none".
selectedRowIds bindable string[] [] Bound selected row ids. Arrays stay arrays on update; Sets stay Sets. When omitted, DataTable starts with an empty array.
getRowId (row: Row, index: number) => string Resolves the stable row id used for selection. Defaults to row.id when it is a string or number, otherwise the row's current positional index.
isRowSelectionDisabled (row: Row, index: number) => boolean Returns true when a row should render a disabled selection checkbox.
selectAllLabel text 'Select all rows' Accessible label for the multiple-selection header checkbox.
rowSelectionLabel (row: Row, index: number) => string Accessible label for an individual row selection checkbox.
stickyHeader boolean false When true, the header sticks to the top of the scrolling container.
density 'comfortable' | 'condensed' | 'spacious' 'comfortable' Vertical padding density for header and body cells. Defaults to 'comfortable'.
scrollable boolean true Draws the table inside the same scroll box a Table uses: it owns the border, the radius and the clip, scrolls sideways when the columns do not fit, and fades at the inline end. A virtualized table always scrolls in this box.
stackBelow text '640px' Width of the table's own container below which a table with a controls column stacks, each row becoming a card with the controls on a line of their own. See Table.
cell snippet Draws the content of every body cell, in place of the plain value, for cells that hold more than text: a checkbox, a select, a name with its identifier beneath. Render {context.value} for a column that needs nothing special.
rowMessage snippet Draws a message across the full width of the table directly under a row, such as the line that says a save failed. It is a row of its own, not squeezed into a cell, and it belongs to the row above it. Which rows have one is hasRowMessage. Give the message role="alert" when it reports a failure, so it is announced.
hasRowMessage (row: Row, index: number) => boolean Whether a row has a message under it. Without it, every row has one while rowMessage is set.
groupBy (row: Row, index: number) => DataListGroup Groups consecutive rows under a header row that spans the table, such as a day. Each run of rows with the same group key follows one header, drawn as the group's label and, after a dot, its detail (the time zone). Rows are not reordered; pass them already sorted. Ignored while virtualized.
footer snippet Content of a footer row that spans the table, below the last row: a count, a hint. The table stays one framed box.
onReachEnd (() => void) | undefined Called when the end of the table scrolls into view, and again after rows grows while the end is still in view, so a table loads more rows by scrolling and needs no button. Pass it only while there are more rows to load, and guard against a load already in flight.
openRowId text null Id of the open row, the one a detail pane shows. It is marked aria-current and drawn highlighted. Ids are the ones getRowId returns.
onRowOpen (row: Row, index: number) => void Makes each row open on a click, Enter or Space, and gives the rows one tab stop with Arrow keys, Home and End moving between them. A click on a control inside the row (a button, a link, a field) does not open it.
resizable boolean false Enables pointer and keyboard resizing handles in column headers.
onColumnResize (columnKey: string, width: number) => void Called after a column width changes through a pointer or keyboard resize handle.
virtualized boolean false When true, renders only the visible <tbody> row window plus spacer rows. Requires a fixed row height. This is intended for large, append-only tables such as live logs or event streams.
rowHeight number 44 Fixed body row height in pixels for virtualized mode. This must match the actual rendered body row height, including density padding and any wrapping introduced by the table content. Defaults to 44.
overscan number 5 Extra body rows rendered before and after the visible virtualized window. Defaults to 5.
height text '24rem' CSS block-size for the virtualized native scroll container. Defaults to "24rem" when virtualized is true.
stickToBottom boolean false When true in virtualized mode, appending rows while scrolled to the bottom keeps the newest row pinned in view. Appending while scrolled up does not change the viewport.
onscroll UIEventHandler<T> | undefined | null