Record Grid
FreeThe data table's `responsive="records"`: a table that becomes a list of records when there is no room to be a table. Below the breakpoint the markup stops claiming to be a table and becomes a list of real <dl> label/value pairs — the structure HTML already has for this — with sorting, selection and row actions rebuilt rather than lost, and nothing dropped.
Complexity tier: Application The interactive bar, plus a stated data-volume ceiling, a persistence contract, a bundle budget and an accessible parity surface.
import { SvDataTableComponent } from '@styloviz/data-table';Demo & usage
Basic usage
Usage example — open the gallery for the full interactive demo.
An interactive demo for this component lives in the gallery.
Open live demoMore examples
Why not the CSS trick
The technique everyone reaches for sets display:block on the table elements and pipes the column header into each cell through a data-label and a ::before. Two things go wrong and both are invisible. The moment those elements stop being display:table-* the browser drops their table roles, so a screen reader is handed a pile of anonymous blocks instead of rows and columns. And generated content from ::before is not text a user can select, search for or copy. The result looks like labelled cards and is less accessible than the table it replaced.
<!-- What this renders below the breakpoint: a list of records, each a real description list. Not a table pretending to be blocks. --> <ul role="list"> <li> <article aria-labelledby="..."> <h3 id="...">Ada Lovelace</h3> <dl> <div><dt>Status</dt><dd>Shipped</dd></div> <div><dt>Total</dt><dd>£42.00</dd></div> </dl> </article> </li> </ul>
Nothing is dropped
The other common answer to a table that does not fit is to hide the columns that do not. A table that silently drops three of its eight fields on a phone is not a responsive table, it is a different table, and nobody is told which one they are reading. A column marked priority: 'secondary' moves behind a per-card disclosure that says how many are in it.
readonly columns: TableColumn[] = [ { key: 'customer', label: 'Customer' }, { key: 'total', label: 'Total', sortable: true }, { key: 'reference', label: 'Reference', priority: 'secondary' }, { key: 'channel', label: 'Channel', priority: 'secondary' }, ];
Sorting has nowhere to live in a card list
The table's sort affordance is the header cell, and a card list has no headers — so a table that becomes cards loses sorting unless the control is rebuilt somewhere else. The records view rebuilds it as a labelled select and a named direction button, and both drive the table's own sort: client-side it reorders, server-side it emits, and switching views never loses it.
<sv-data-table [columns]="columns" [rows]="rows" responsive="records" [selectable]="true" [(selectedIds)]="picked" (sortChange)="onSort($event)" />
A narrow panel on a wide screen
A media query measures the viewport, not the panel the table sits in. Where you know the space is narrow, show the records at any width.
<sv-data-table [columns]="columns" [rows]="rows" responsive="records" recordView="always" /> <!-- or move the switch: [recordBreakpoint]="900" -->
When to use
Any data table that has to work on a phone — which is most of them. A table embedded in a narrow panel on a wide screen: set `recordView="always"`, because a media query cannot see the panel. For a compact card per row with every column shown (and windowed under `virtualized` on the Pro table), `responsive="cards"` is the lighter option. For a genuinely small set of fields per record, a Descriptions list on its own may be all you need.
Async states
- loading
- empty
- error
- retry
- partial
Item identity & owned state
- Item key
rowKey— set this when your rows have noid, so selection survives a reorder.- Restorable state
- expandedRowIds
- hiddenColumnKeys
- recordExpandedIds
- revealedColumnKeys
- selectedIds
Bind these to put a saved view back — the open sections, the hidden columns, the selected rows — and read their
Changeevents to store what the user does.
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
| columns | TableColumn<T>[] | [] | Column definitions (key, header, alignment, optional cell template). |
| rows | readonly T[] | [] | The rows to render. `readonly` on purpose: the table never mutates this array, and anything that hands it one — a signal, a `computed`, `svDataController.items` — is handing over a value it still owns. A mutable `T[]` here rejected every one of those at the template boundary while promising a write the table does not perform. |
| rowKey | SvItemKey<T> | 'id' | What identifies a row: a property name, or a function for composite keys. Widened from `string` because a row identified by two fields — an order line keyed on `orderId` + `lineNo`, a matrix cell on `row` + `col` — had no way to say so, and the fallback silently keyed it on the whole row's JSON. See the identity contract on `resolveItemKey` in `@styloviz/core`. |
| selectable | boolean | false | Enable row selection. |
| selectMode | SelectMode | 'multi' | 'multi' = checkboxes, 'single' = radio buttons. |
| selectedIds | Set<string | number> (two-way) | new Set() | Selected row ids (two-way). |
| expandedRowIds | Set<string | number> (two-way) | new Set() | Which rows have their detail panel open (two-way). A `model` rather than internal state because it is the same kind of fact as `selectedIds`: a host restoring a table after a route change, or opening the row a deep link names, has to be able to write it — and one that persists layout has to be able to see it change. Held in a plain signal it was neither settable nor observable from outside. |
| actions | TableRowAction<T>[] | [] | Per-row action buttons. |
| bulkActions | BulkAction[] | [] | Bulk actions applied to selected rows. |
| loading | boolean | false | Show a loading state. |
| loadingStyle | LoadingStyle | 'skeleton' | 'skeleton' rows or full-table 'overlay' spinner. |
| skeletonRows | number | 5 | Number of skeleton rows while loading. |
| paginated | boolean | true | Enable client-side pagination. |
| pageSize | number (two-way) | 10 | Rows per page (two-way). |
| pageSizeOptions | number[] | [10, 25, 50] | Page-size options offered in the toolbar. |
| serverSide | boolean | false | Server-side mode: disables client filtering/sorting/paging. |
| totalCount | number | null | null | Total row count when in server-side mode. |
| variant | TableVariant | 'default' | Table style variant. |
| density | TableDensity | 'comfortable' | Row density: comfortable, compact, etc. |
| maxHeight | string | null | null | Max body height (CSS length) before the table scrolls. |
| showScrollHint | boolean | true | Show a hint when the table is horizontally scrollable. |
| rowClassFn | ((row: T) => string) | null | null | Callback returning extra Tailwind classes for a given row. |
| showToolbar | boolean | undefined | undefined | Show the toolbar strip. Left unset it is derived from whether the toolbar has anything to put in it: a `tableTitle`, or any control it holds — `searchable`, `showDensityToggle`, `showColumnToggle` or `exportable`. Set it explicitly to force the strip on (an empty bar as a spacer) or off (a title used only as the accessible name, or the controls dropped). |
| tableTitle | string | '' | Title shown in the toolbar. |
| searchable | boolean | false | Show a search box in the toolbar. |
| showColumnToggle | boolean | false | Show the column visibility toggle. |
| exportable | boolean | false | Show an export (CSV) control. |
| showDensityToggle | boolean | false | Show the density toggle. |
| columnFilters | boolean | false | Enable per-column filters. |
| multiSort | boolean | false | Allow sorting by multiple columns. |
| expandable | boolean | false | Enable expandable rows. |
| expandRender | ((row: T) => string) | null | null | Renderer for the expanded row detail. |
| showFooter | boolean | false | Show a table footer row. |
| responsive | DataTableResponsive | 'none' | What the table becomes when there is no room to be a table — see `DataTableResponsive`. `'none'` keeps the table and scrolls it sideways; `'cards'` shows a compact label/value card per row below the `sm` breakpoint; `'records'` shows a list of records below `recordBreakpoint`. |
| recordTitleKey | string | '' | `responsive="records"`: the column that titles each record. Empty uses the first shown column. |
| recordBreakpoint | number | 768 | `responsive="records"`: width below which the records replace the table, in px. |
| recordView | DataTableRecordView | 'auto' | `responsive="records"`: `'always'` shows the records at any width — a narrow panel on a wide screen. |
| recordExpandedIds | ReadonlySet<string | number> (two-way) | new Set() | `responsive="records"`: row keys whose secondary fields are open (two-way), keyed by `rowKey`, never by position, so a host can restore them. |
| emptyMessage | string | 'No data to display.' | Message shown when there are no rows. |
| customClass | string | '' | Extra CSS classes for the root element. |
| error | SvDataError | string | null | null | Load failure. Use `toSvDataError()` from `@styloviz/core` to normalize an `HttpErrorResponse`. Rendered in place of the rows, above the toolbar so the user can still change the filter that caused it. |
| debounceMs | number | 300 | Milliseconds typing in the search box or a text column filter waits before `queryChange` asks the server again (`serverSide` only). The rows on screen still filter on every keystroke; sorting, paging and clearing ask at once. `0` asks on every keystroke. |
| hiddenColumnKeys | Set<string> (two-way) | new Set() | Which columns the user has hidden (two-way). Bind it to restore a saved set of hidden columns, and read `(hiddenColumnKeysChange)` to store what the user changes. |
| revealedColumnKeys | ReadonlySet<string> (two-way) | new Set() | Columns declared `hidden: true` that the user has since shown from the Columns menu. A `hidden` column starts hidden and stays in the Columns menu, so the user can show it. Two-way, like `hiddenColumnKeys`: together the two ARE the column-visibility view, and a host that persists one without the other restores a table whose revealed columns have vanished again. |
Outputs
| Event | Payload type | Description |
|---|---|---|
| sortChange | SortState[] | Emitted with the new sort state when sorting changes. |
| selectionChange | Set<string | number> | Emitted with the set of selected row ids. |
| rowClick | T | Emitted with the clicked row. |
| cellClick | CellClickEvent<T> | Emitted with the clicked cell context. |
| editComplete | EditCompleteEvent<T> | Emitted when an inline cell edit completes. |
| retry | void | The host should re-run the failed load. |
| queryChange | SvDataQuery | Everything the user is asking to see, in the kit's shared shape. This is the output to wire in `serverSide` mode: one handler regardless of whether they paged, sorted, filtered or searched, and the same `SvDataQuery` every other component in the kit emits — so `@styloviz/data` and a hand-rolled fetch both take it without a translation layer. |
| rowExpand | T | Emitted with the row when the user expands or collapses its detail panel. |
| bulkActionClick | { action: BulkAction; selectedIds: Set<string | number> } | Emitted with the bulk action and the selected row ids. |
| selectedIdsChange | Set<string | number> | Emits the new `selectedIds` whenever it changes — the output half of `[(selectedIds)]`. |
| expandedRowIdsChange | Set<string | number> | Emits the new `expandedRowIds` whenever it changes — the output half of `[(expandedRowIds)]`. |
| pageSizeChange | number | Emits the new `pageSize` whenever it changes — the output half of `[(pageSize)]`. |
| recordExpandedIdsChange | ReadonlySet<string | number> | Emits the new `recordExpandedIds` whenever it changes — the output half of `[(recordExpandedIds)]`. |
| hiddenColumnKeysChange | Set<string> | Emits the new `hiddenColumnKeys` whenever it changes — the output half of `[(hiddenColumnKeys)]`. |
| revealedColumnKeysChange | ReadonlySet<string> | Emits the new `revealedColumnKeys` whenever it changes — the output half of `[(revealedColumnKeys)]`. |
<sv-data-table-pro>
Also in this family — SvDataTableProComponent from @styloviz-pro/data-table.
Async states
- loading
- empty
- error
- retry
- partial
Item identity & owned state
- Item key
rowKey— set this when your rows have noid, so selection survives a reorder.- Restorable state
- expandedRowIds
- hiddenColumnKeys
- recordExpandedIds
- revealedColumnKeys
- selectedIds
Bind these to put a saved view back — the open sections, the hidden columns, the selected rows — and read their
Changeevents to store what the user does.
Server writes
- Writes
- batchSave
Each payload carries a
requestKey— send it with the request so a retry cannot apply the same change twice.- Rollback
- Call
event.rollback()when the save fails — the change is already on screen, and this is what puts it back. - While saving
- Bind
saving— with two writes outstanding there is no single state to roll back to, so the action stays locked until the first one lands. - On failure
- Pass the failure to
saveErrorto show it in place — without taking away what the user was working on.
Saved state
- Stored kinds
- sv-data-table/layout
What you will find under your own storage key. You choose the key; the blob names its own
kindand schemaversion, so a component never reads state another one wrote.- Reading it back
- Restore through the component's own
restore…helper rather than casting the parsed JSON. A blob from an older release is migrated where it can be and refused with a reason where it cannot — so an upgrade never silently applies last month's shape to this month's fields.
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
| columns | TableColumn<T>[] | [] | Column definitions: key, label, alignment, and each column's sorting, filtering, rendering and editing options. |
| rows | readonly T[] | [] | The rows to render. `readonly` on purpose: the table never mutates this array, and anything that hands it one — a signal, a `computed`, `svDataController.items` — is handing over a value it still owns. A mutable `T[]` here rejected every one of those at the template boundary while promising a write the table does not perform. |
| rowKey | SvItemKey<T> | 'id' | What identifies a row: a property name, or a function for composite keys. Widened from `string` because a row identified by two fields — an order line keyed on `orderId` + `lineNo`, a matrix cell on `row` + `col` — had no way to say so, and the fallback silently keyed it on the whole row's JSON. See the identity contract on `resolveItemKey` in `@styloviz/core`. |
| selectable | boolean | false | Add a selection column of checkboxes (or radio buttons, per `selectMode`). |
| selectMode | SelectMode | 'multi' | 'multi' = checkboxes, 'single' = radio buttons. |
| selectedIds | Set<string | number> (two-way) | new Set() | Ids of the selected rows, as resolved by `rowKey` (two-way). |
| expandedRowIds | Set<string | number> (two-way) | new Set() | Which rows have their detail panel open (two-way). A `model` rather than internal state because it is the same kind of fact as `selectedIds`: a host restoring a table after a route change, or opening the row a deep link names, has to be able to write it — and one that persists layout has to be able to see it change. Held in a plain signal it was neither settable nor observable from outside. |
| actions | TableRowAction<T>[] | [] | Per-row actions, offered in a menu at the end of each row; an action's `hidden` callback can drop it for a given row. |
| bulkActions | BulkAction[] | [] | Actions shown in a bar above the table while any row is selected; each receives the selected ids and also emits `bulkActionClick`. |
| loading | boolean | false | Show the loading state (skeleton rows or an overlay spinner, per `loadingStyle`) and mark the table `aria-busy`. |
| loadingStyle | LoadingStyle | 'skeleton' | 'skeleton' rows or full-table 'overlay' spinner. |
| skeletonRows | number | 5 | Number of placeholder rows (and mobile cards) rendered while `loading` with the skeleton style. |
| paginated | boolean | true | Split rows into pages with a pagination bar. Has no effect when `virtualized` or `groupBy` is set. |
| pageSize | number (two-way) | 10 | Rows per page (two-way); also updated when the user picks a size in the pagination bar. |
| pageSizeOptions | number[] | [10, 25, 50] | Choices in the pagination bar's rows-per-page select; an empty array hides the select. |
| serverSide | boolean | false | Server-side mode: disables client filtering/sorting/paging. |
| totalCount | number | null | null | Total row count across all pages in `serverSide` mode, used for the range label and page count; falls back to `rows.length` when null. |
| virtualized | boolean | false | Windows row rendering to what's scrolled into view, using the same variable-height primitive (`createVariableVirtualizer`, `@styloviz/core`) `list-view` uses — a group header and a data row are different heights, so this table always needs the variable form, never the fixed one. Ignores `paginated`: virtualization and client pagination solve the same problem (a huge row set costing too much DOM), so turning this on reads as opting OUT of pagination rather than stacking both — the same relation `groupBy` has to pagination, and for the same reason. |
| virtualRowHeight | number | 44 | Approximate pixel height of one data row; the virtualized window is computed from it. Approximate, like `list-view`'s `itemHeight`: measure your own rendered row height for pixel accuracy. A wrong guess still renders every row correctly, with a slightly-off scrollbar length until the next scroll event corrects it. |
| virtualGroupRowHeight | number | 40 | Pixel height of a collapsible group header row, when `groupBy` is also set. |
| cardRowHeight | number | 96 | Pixel height of one `responsive="cards"` card; the card list is windowed from it, on the same `virtualized` switch as the table. A card is taller than a row and its height depends on how many columns are visible — a two-column grid of label/value pairs, so roughly `ceil(columns / 2) * 46 + 32`. Approximate for the same reason `virtualRowHeight` is: a wrong guess costs scrollbar accuracy, never correctness. |
| viewportHeight | number | 400 | Pixel height of the scrolling viewport when `virtualized` is on. A dedicated numeric input rather than reusing `maxHeight` — `maxHeight` accepts any CSS unit (`'50vh'`, `'none'`) that cannot be safely coerced to a pixel count, and the windowing math needs a real number to divide by. |
| groupBy | string | null | null | Column key to section rows by, with a collapsible header per distinct value. Single-level only — a deliberate scope line: nested/multi-level grouping (which parent collapses which children, aggregate-of-aggregates) is real complexity no showcase use case has asked for, and this shape is additive if a future version needs it. |
| defaultGroupsExpanded | boolean | true | Whether a group starts expanded or collapsed the first time it's seen. |
| variant | TableVariant | 'default' | Visual style: 'default', 'striped' (tinted alternate rows), 'bordered' (cell borders) or 'borderless' (no outer border or row dividers). |
| layout | TableLayout | 'default' | Layout mode. 'comparison' transposes rows into columns for a product-comparison grid. |
| highlightRowId | string | number | null | null | rowKey value of the product column to highlight as "recommended" in comparison layout. |
| transparent | boolean | false | Removes the table's own surface fill (root, toolbar, body and rows) so it inherits the background of its container — e.g. when nested inside a glass card or a coloured panel. Row hover/selection tints and the `striped` variant's odd-row tint are preserved. Also drops the card shadow. |
| density | TableDensity | 'comfortable' | Row padding and text size: 'compact', 'comfortable' or 'spacious'. A choice made in the density toggle overrides it. |
| maxHeight | string | null | null | Maximum height (any CSS length) of the table's scroll area before it scrolls vertically; ignored when `virtualized`, which uses `viewportHeight`. |
| showScrollHint | boolean | true | Show a fade gradient along the right edge hinting that the table scrolls horizontally. |
| rowClassFn | ((row: T) => string) | null | null | Callback returning extra Tailwind classes for a given row. |
| showToolbar | boolean | undefined | undefined | Show the toolbar strip. Left unset it is derived from whether the toolbar has anything to put in it: a `tableTitle`, or any control it holds — `searchable`, `showDensityToggle`, the Columns panel, `findable`, the filter builder, `printable`, or `exportable` with a format to offer. Set it explicitly to force the strip on (an empty bar as a spacer) or off (a title used only as the accessible name, or the controls dropped). Derived, it is also on for `reorderableColumns` / a resizable column: the Columns panel holds those drags' single-pointer alternatives (WCAG 2.5.7). Forcing it off removes them — keep the toolbar when either drag is on. |
| tableTitle | string | '' | Heading shown in the toolbar; also the table's accessible name and the title of Excel and PDF exports. |
| searchable | boolean | false | Show a toolbar search box that filters rows by text in any column (sent as `search` in `serverSide` mode). |
| showColumnToggle | boolean | false | Show a toolbar menu for hiding and showing columns. |
| exportable | boolean | false | Show a toolbar export control offering the formats in `exportFormats`. |
| exportFormats | readonly TableExportFormat[] | ['csv'] | Which formats the export control offers, in menu order. One format renders a plain button; more than one renders a menu. Defaults to CSV alone, so `[exportable]="true"` on its own offers a CSV button. Excel and PDF are opt-in: a table offers them only where the host asks (both load `@styloviz-pro/export` as a lazy chunk on first use, and a PDF with fonts set also loads its text shaper then). |
| exportFileName | string | '' | Base filename for exports, without extension. |
| showDensityToggle | boolean | false | Show a toolbar control that lets the user switch row density. |
| columnFilters | boolean | false | Add a filter row beneath the header with a text or select filter per column (per each column's `filterType`). |
| multiSort | boolean | false | Let Shift+click on a header add a secondary sort instead of replacing the current one. |
| resizableColumns | boolean | false | Allow users to drag column edges to resize; the toolbar's Columns panel also offers Narrow / Widen buttons (WCAG 2.5.7). |
| reorderableColumns | boolean | false | Allow users to drag headers (or Ctrl/Cmd+←/→) to reorder columns; the toolbar's Columns panel also offers Move left / Move right buttons (WCAG 2.5.7). |
| expandable | boolean | false | Add a toggle to each row that opens a detail panel beneath it. |
| expandRender | ((row: T) => string) | null | null | Returns the plain text shown in an expanded row's detail panel; when null, the panel lists every column's label and value. |
| showFooter | boolean | false | Show the summary footer row built from each column's `footerFn`; nothing renders unless at least one column defines one. |
| responsive | DataTableResponsive | 'none' | What the table becomes when there is no room to be a table — see `DataTableResponsive`. `'none'` keeps the table and scrolls it sideways; `'cards'` shows a compact label/value card per row below the `sm` breakpoint; `'records'` shows a list of records below `recordBreakpoint`. |
| recordTitleKey | string | '' | `responsive="records"`: the column that titles each record. Empty uses the first shown column. |
| recordBreakpoint | number | 768 | `responsive="records"`: width below which the records replace the table, in px. |
| recordView | DataTableRecordView | 'auto' | `responsive="records"`: `'always'` shows the records at any width — a narrow panel on a wide screen. |
| recordExpandedIds | ReadonlySet<string | number> (two-way) | new Set() | `responsive="records"`: row keys whose secondary fields are open (two-way), keyed by `rowKey`, never by position, so a host can restore them. |
| cellSelection | boolean | false | Select a block of cells: drag, Shift+click or Shift+arrows (Ctrl+A all, Shift+Space a row, Ctrl+Space a column); Ctrl/⌘+C copies it as text a spreadsheet reads, Ctrl/⌘+V pastes into it, the corner handle fills (Ctrl+D / Ctrl+R without the drag). The table becomes a `role="grid"`. Writes arrive as one `rangeEdit`; the table never changes `rows`. |
| cellRange | SvCellRange | null (two-way) | null | The selected block (two-way), by row key and column key. `null` with nothing selected. |
| contextMenu | boolean | false | Right-click (or Shift+F10 / the menu key) on a cell: copy, fill, export the selection, pin or hide the column. |
| findable | boolean | false | Find in the table — Ctrl/⌘+F inside it, or the toolbar's Find. Marks every match and walks them; unlike search, it hides nothing. |
| rowNumbers | boolean | false | A leading column numbering the rows through the whole list (page offsets included). |
| columnBands | readonly SvColumnBand[] | [] | Headings over runs of columns — a multi-level header. See `SvColumnBand`. |
| columnPins | Readonly<Record<string, SvColumnPin>> (two-way) | {} | Columns pinned from the context menu (two-way), over each column's own `pinned`: `'left'` / `'right'` (the inline start / end) or `'none'`. Saved with the layout as `columnPins`. |
| batchEdit | boolean | false | Edits, pastes and fills become an undoable draft (Ctrl/⌘+Z, Ctrl/⌘+Shift+Z) the table shows and marks, saved in one `batchSave` — instead of `editComplete` / `rangeEdit` per change. |
| saving | boolean | false | A `batchSave` is in flight: Save, Discard, Undo and Redo wait for it. |
| saveError | SvDataError | string | null | null | The last `batchSave` failed — shown on the batch bar. Call that save's `rollback()` too. |
| setFilters | Readonly<Record<string, readonly string[]>> (two-way) | {} | `filterType: 'set'` filters (two-way): column key → the values let through. Saved with the layout. |
| filterBuilder | boolean | false | A toolbar Filter builder — `@styloviz-pro/query-builder` over the columns (`queryType` per column). |
| filterQuery | SvQueryExpression | null (two-way) | null | The builder's AND/OR query (two-way) — store it with `svSerializeQuery`. `null` filters nothing. |
| highlightQuery | SvQueryExpression | null (two-way) | null | Rows to mark without hiding the rest (two-way), in the builder's query shape — `svGridAssist` sets it from "highlight …". `null` marks nothing. |
| statusBar | boolean | false | A bar under the table: the row count, or count / sum / average / min / max of the selected cells. |
| printable | boolean | false | A toolbar Print button; printing then shows every filtered row and none of the table's controls. |
| emptyMessage | string | 'No data to display.' | Text shown when there are no rows to display. |
| customClass | string | '' | Extra CSS classes appended to the root element. |
| error | SvDataError | string | null | null | Load failure. Use `toSvDataError()` from `@styloviz/core` to normalize an `HttpErrorResponse`. Rendered in place of the rows, above the toolbar so the user can still change the filter that caused it. |
| debounceMs | number | 300 | Milliseconds typing in the search box or a text column filter waits before `queryChange` asks the server again (`serverSide` only). The rows on screen still filter on every keystroke; sorting, paging and clearing ask at once. `0` asks on every keystroke. |
| hiddenColumnKeys | Set<string> (two-way) | new Set() | Which columns the user has hidden (two-way). Bind it to restore a saved set of hidden columns, and read `(hiddenColumnKeysChange)` to store what the user changes. |
| revealedColumnKeys | ReadonlySet<string> (two-way) | new Set() | Columns declared `hidden: true` that the user has since shown from the Columns menu. A `hidden` column starts hidden and stays in the Columns menu, so the user can show it. Two-way, like `hiddenColumnKeys`: together the two ARE the column-visibility view, and a host that persists one without the other restores a table whose revealed columns have vanished again. |
Outputs
| Event | Payload type | Description |
|---|---|---|
| sortChange | SortState[] | Emitted with the full list of active sorts (empty when cleared) whenever the user changes the sort. |
| selectionChange | Set<string | number> | Emitted with the new set of selected row ids whenever the user changes the selection. |
| rowClick | T | Emitted with the row when the user clicks a row or one of its cells, or activates it with Enter. |
| cellClick | CellClickEvent<T> | Emitted with the row, column and displayed value when the user clicks a cell; `rowClick` fires as well. |
| editComplete | EditCompleteEvent<T> | Emitted with the row, column, old and new value when an inline cell edit is committed with a valid, changed value, so the host can persist it. |
| rangeEdit | SvRangeEdit<T> | Many cells at once — a paste or a fill (`cellSelection`): every changed cell, validated, in one event to apply in one go. |
| batchSave | SvBatchSave<T> | `batchEdit`: the draft, saved. Apply `changes`, send `requestKey`, call `rollback()` if it fails. |
| unsavedChange | number | `batchEdit`: how many cells are unsaved, whenever that changes — for a leave-page guard. |
| retry | void | The host should re-run the failed load. |
| queryChange | SvDataQuery | Everything the user is asking to see, in the kit's shared shape. This is the output to wire in `serverSide` mode: one handler regardless of whether they paged, sorted, filtered or searched, and the same `SvDataQuery` every other component in the kit emits — so `@styloviz/data` and a hand-rolled fetch both take it without a translation layer. |
| rowExpand | T | Emitted with the row when the user expands or collapses its detail panel. |
| bulkActionClick | { action: BulkAction; selectedIds: Set<string | number> } | Emitted with the bulk action and a snapshot of the selected row ids when the user runs a bulk action. |
| columnResize | { key: string; width: number } | A column finished resizing (pointer drag or ←/→ on a focused handle) — emits the column key and its new pixel width, so a host can persist the layout. |
| columnOrderChange | string[] | Columns were reordered by drag — emits the full column-key order, left to right. |
| exportFailed | { format: TableExportFormat; error: Error } | An export failed: a chunk that could not load at click time (offline), a font that could not be read, or an `SvPdfTextError` for a letter no PDF font has. The host learns about it here rather than through an unhandled rejection and a button that appears to do nothing. |
| groupToggle | { key: string; collapsed: boolean } | A group was expanded or collapsed by the user, with its new state. |
| layoutStateChange | TableLayoutState | Fires whenever anything `TableLayoutState` describes changes — column order/width/visibility, sort, column filters, page size, or which groups are collapsed — so a host knows there is something new to save. Store `serializeLayoutState()` rather than this payload: the payload is the live shape, while the serialized form carries a kind and a schema version, and `restoreLayoutState()` can then say why it ignored a blob instead of applying one whose shape does not fit the current table. Does not fire for the state the table mounted with, only for a real change after that, so a host writing straight through to storage does not immediately re-save what it just loaded via `applyLayoutState`. |
| selectedIdsChange | Set<string | number> | Emits the new `selectedIds` whenever it changes — the output half of `[(selectedIds)]`. |
| expandedRowIdsChange | Set<string | number> | Emits the new `expandedRowIds` whenever it changes — the output half of `[(expandedRowIds)]`. |
| pageSizeChange | number | Emits the new `pageSize` whenever it changes — the output half of `[(pageSize)]`. |
| recordExpandedIdsChange | ReadonlySet<string | number> | Emits the new `recordExpandedIds` whenever it changes — the output half of `[(recordExpandedIds)]`. |
| cellRangeChange | SvCellRange | null | Emits the new `cellRange` whenever it changes — the output half of `[(cellRange)]`. |
| columnPinsChange | Readonly<Record<string, SvColumnPin>> | Emits the new `columnPins` whenever it changes — the output half of `[(columnPins)]`. |
| setFiltersChange | Readonly<Record<string, readonly string[]>> | Emits the new `setFilters` whenever it changes — the output half of `[(setFilters)]`. |
| filterQueryChange | SvQueryExpression | null | Emits the new `filterQuery` whenever it changes — the output half of `[(filterQuery)]`. |
| highlightQueryChange | SvQueryExpression | null | Emits the new `highlightQuery` whenever it changes — the output half of `[(highlightQuery)]`. |
| hiddenColumnKeysChange | Set<string> | Emits the new `hiddenColumnKeys` whenever it changes — the output half of `[(hiddenColumnKeys)]`. |
| revealedColumnKeysChange | ReadonlySet<string> | Emits the new `revealedColumnKeys` whenever it changes — the output half of `[(revealedColumnKeys)]`. |
Wire it to your API
This component is headless about transport: it renders what you give it and reports what the user asks for. Nothing below requires @styloviz/data — it just saves you writing the debounce, the request guard and the retry policy by hand.
Template
Bound to the names this component actually exposes.
<sv-data-table [serverSide]="true" [rows]="data.items()" [loading]="data.loading()" [error]="data.error()" [totalCount]="data.total()" (queryChange)="data.setQuery($event)" (retry)="data.reload()" />
Host class
One controller handles debounce, request-guarding, cancellation and retry.
import { svDataController, createHttpDataSource } from '@styloviz/data'; /** Your record type — whatever the endpoint returns per item. */ type Row = { readonly id: string }; readonly data = svDataController( createHttpDataSource<Row>({ url: '/api/rows' }), );
`queryChange` carries an `SvDataQuery` — page, page size, sorts, filters, search and cursor in one object. One handler covers every way the user can change what they are asking for. `serverSide` switches **off** the built-in filtering, sorting and paging. Leave it false and the component works entirely from the array you pass — which is what you want for a few hundred rows. `debounceMs` (default 300) collapses a burst of typing into one request. Set it to 0 only when the query is driven by clicks. Normalize failures with `toSvDataError()` from `@styloviz/core`. It derives `retryable` from the status, so a 404 does not get a "Try again" button that can only fail again.
Full walkthrough: Connecting to a backend.
Customization & theming
`responsive="records"` with `recordBreakpoint` (default 768) and `recordView` (`auto` / `always`) decides when the records replace the table; `auto` measures the viewport with `matchMedia`, re-measuring when the breakpoint changes, and only while `responsive` is `records`. `recordTitleKey` promotes one field to the record heading; `priority: 'secondary'` on a column moves it behind the per-record disclosure. Selection, sort, `actions` (each `handler` runs), paging, loading and the empty message are the table's own, shared by both views. Two-way `recordExpandedIds` holds which records have their secondary fields open, keyed by `rowKey`, so a host can restore it. Both tiers: `sv-data-table` (`@styloviz/data-table`) and `sv-data-table-pro` (`@styloviz-pro/data-table`). `responsive="records"` is the record-list layout in both.
Best practices
Do: Set `recordTitleKey` to the field a reader would use to identify the record. A `<dl>` cannot supply a heading — every pair in it is equally a term — so one field is promoted out, and the default (the first column) is rarely the best one. Do: Mark the fields that matter least as `priority: 'secondary'` rather than removing them from `columns`. They move behind a disclosure that says how many are in it. Do: Use the table's own sort and selection — `(sortChange)`, `[(selectedIds)]`. The records view drives the same state, so switching views never loses a sort or a ticked row. Do: Set `rowKey`. Tracking by position reuses one record's DOM for another on the next sort or page, so a checkbox stays ticked while the record under it changes. Don't: Don't reach for the `display: block` CSS trick instead. It drops the table roles and replaces selectable text with generated content — it looks like this and is less accessible than the table it replaced.
Accessibility
Keyboard at scale: the records view renders the page the table is on, so the table's paging bounds it. Below the breakpoint the markup **stops claiming to be a table**. It is a `<ul role="list">` of `<article>` cards, each labelled by its own heading and holding a real `<dl>` of `<dt>`/`<dd>` pairs — which is what a screen reader announces as "Status, definition, Shipped". The labels are real text, not `::before` generated content, so they can be selected, searched and copied. Every control names the record it acts on — "Select Grace Hopper", "Refund Grace Hopper", "Show 2 more fields for Ada Lovelace" — because a card list has no row context to fall back on. The sort control is a labelled `<select>` with a named direction button rather than an icon, since a list of records has no header cell to carry the affordance. A server render shows the table, because a prerender cannot measure and the table is the view that holds every field and every label.
Feedback on Record Grid
Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.