Component
DataTable
A table driven by `createDataTable()`: sorting, search, filters, paging, selection and in-place editing.
import { DataTable } from '@loidolt/theme-svelte';
Example
| Birch ply | Ready | 1 | Sep 1 | ||
| Birch ply | Ready | 2 | Sep 9 | ||
| Birch ply | Ready | 3 | Sep 17 | ||
| Birch ply | Ready | 4 | Sep 25 | ||
| Birch ply | Ready | 5 | Sep 5 | ||
| Birch ply | Ready | 6 | Sep 13 | ||
| Mount board | In review | 8 | Sep 2 | ||
| Mount board | In review | 9 | Sep 10 |
1–8 of 42
Notes
- State lives in
createDataTable(), not the component, so the search, filter, column and pagination parts all drive the same table — and you can read or change it from code. - Pass
datathrough a getter (get data() { return rows; }) to keep the table in step with changing rows. - Paged or virtual, the table reports
aria-rowcountand each row itsaria-rowindex, so screen readers announce "row 27 of 43" rather than "row 2 of 8". selection: 'multiple'adds a checkbox column with a select-all that is indeterminate when some rows on the page are selected.'single'uses radios.editablecolumns become buttons that turn into a field: Enter or leaving saves throughonCellEdit, Escape restores the old value.hideBelowdrops a column on narrow screens while keeping it searchable and sortable.virtualrenders only the rows in view; rows must have a fixed height and the wrapper needsstickywith--ldt-table-height.- For server data set
manualandrowCount, and fetch in theon…Changecallbacks.
Props
Generated from the component source, so it cannot drift from the implementation.
| Prop | Type | Default | Notes |
|---|---|---|---|
table required | DataTableState<T> | — | The state from createDataTable(). |
caption | string | — | |
class | string | — | class lands on the <table>; wrapperClass on the scroll container. |
editLabel | (header: string) => string | (header) => `Edit ${header}` | |
empty | Snippet | — | Shown when no rows remain. Defaults to an EmptyState from emptyTitle. |
emptyDescription | string | — | |
emptyTitle | string | 'No results' | |
loading | boolean | false | Show placeholder rows while data is on its way. |
loadingRows | number | 5 | |
onCellEdit | (row: T, columnId: string, value: string) => void | — | Called when an editable cell is saved. Update your data in response. |
ref bindable | HTMLTableElement | null | null | |
regionLabel | string | — | |
row | Snippet<[DataTableRow<T>]> | — | Render each row yourself. Receives the row; output a whole <tr>. |
selectAllLabel | string | 'Select all rows on this page' | |
selectLabel | (row: T) => string | () => 'Select row' | Accessible name of a row's selection control. |
sticky | boolean | false | Pin the header row. Needs --ldt-table-height on the wrapper. |
virtual | { rowHeight: number; overscan?: number } | — | Render only the rows scrolled into view — for thousands of rows on one page. Every row must be rowHeight pixels tall, and the wrapper needs --ldt-table-height (with sticky). |
wrapperClass | string | — | |
wrapperRef bindable | HTMLDivElement | null | null |
Plus the attributes of Omit<HTMLTableAttributes, 'children'>, forwarded to the root element.