0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Progressive enhancement wrapper for HTML tables. Adds sorting, filtering, pagination, row expansion, and selection.
Overview
The <data-table> component wraps a standard HTML table to provide interactive features like column sorting, text filtering, pagination, expandable rows, row selection with bulk actions, responsive card layouts, and sticky headers/columns. All features are opt-in via data attributes and the table remains fully functional without JavaScript.
Wrap any HTML table with <data-table> and add data attributes to enable features. The table structure remains semantic and accessible.
Sortable columns example
12345678910111213141516171819
<data-table><table><thead><tr><thdata-sort="string">Name</th><thdata-sort="string">Email</th><thdata-sort="string">Department</th></tr></thead><tbody><tr><td>Alice Johnson</td><td>[email protected]</td><td>Engineering</td></tr><!-- More rows... --></tbody></table></data-table>
Sorting
Add data-sort to any <th> element to make that column sortable. The component wraps the header text in a native <button> (the APG sortable table pattern), so headers are reachable with Tab, show a focus ring, and sort with Enter or Space. Activating a header toggles between ascending and descending; activating a different column sorts it ascending (or descending if the rows are already in ascending order, so the change is always visible). The arrow indicator and aria-sort on the <th> always agree.
Sort Types
Value
Description
string
Alphabetical sorting (case-insensitive)
number
Numeric sorting (handles decimals and negatives)
date
Date sorting (parses common date formats)
Custom Sort Values
Use data-sort-value on cells when the display value differs from the sort value. This is required for formatted numbers: data-sort="number" parses the cell with parseFloat, so text like $1,234 or 1,234 would not sort numerically without a raw value.
Custom sort values
1234
<!-- Display shows formatted value, sorts by raw value --><tddata-sort-value="95000">$95,000</td><tddata-sort-value="1234.5">1,234.50</td><tddata-sort-value="2019-03-15">Mar 15, 2019</td>
Filtering
Add data-filterable to the table to enable text filtering. A search input is automatically generated above the table. Rows that don't match the filter text are hidden, and the result count is announced to screen readers. When nothing matches, a visible “No matching rows found” message appears below the table; override its text (and the announcement) with data-label-no-results on <data-table>. The other generated strings are covered in Localizing the labels.
Filterable table
12345678910111213141516171819
<data-table><tabledata-filterable><thead><tr><th>Name</th><th>Email</th><th>Department</th></tr></thead><tbody><!-- Rows will be filtered as user types --></tbody></table></data-table><!-- Localised empty state --><data-tabledata-label-no-results="Aucun résultat"><tabledata-filterable>...</table></data-table>
Pagination
Add data-paginate="n" to the table to show only n rows per page. Pagination controls are automatically generated below the table.
Paginated table
123456789101112131415
<data-table><tabledata-paginate="5"><thead><tr><th>Name</th><th>Email</th><th>Department</th><th>Hire Date</th></tr></thead><tbody><!-- 12 rows, showing 5 per page --></tbody></table></data-table>
Row Expansion
Create expandable rows by adding data-expandable to a row and following it with a data-expand-content row. Put your own toggle button in the row with data-action="toggle-expand" (give it an accessible name); the component wires it up, keeps aria-expanded in sync, and keeps the content row attached to its parent when sorting, filtering, or paging.
Expandable rows
12345678910111213141516171819202122232425
<data-table><table><thead><tr><th></th><th>Name</th><th>Department</th><th>Status</th></tr></thead><tbody><trdata-expandable><td><buttontype="button"data-action="toggle-expand"aria-label="Details for Alice Johnson">+</button></td><td>Alice Johnson</td><td>Engineering</td><td>Active</td></tr><trdata-expand-contenthidden><tdcolspan="4"><div>Additional details here...</div></td></tr></tbody></table></data-table>
Row Selection
Add checkboxes to rows for selection, with a "select all" checkbox in the header and a bulk actions bar that appears when rows in that table are selected. The selection count is announced to screen readers. Selected rows get data-state-selected, which uses the same selected tint as a native tr[data-selected], plus a non-colour cue.
Row selection with bulk actions
123456789101112131415161718192021222324252627
<data-table><divdata-bulk-actionshidden><span><strongdata-selected-count>0</strong> selected</span><button>Export</button><button>Archive</button><button>Delete</button></div><table><thead><tr><th><inputtype="checkbox"data-action="select-all"/></th><th>Name</th><th>Email</th><th>Department</th></tr></thead><tbody><trdata-selectable><td><inputtype="checkbox"data-action="select-row"/></td><td>Alice Johnson</td><td>[email protected]</td><td>Engineering</td></tr><!-- More selectable rows... --></tbody></table></data-table>
Responsive Card Mode
Add data-responsive="card" to transform the table into a card layout on narrow screens. Each cell's label is derived from its column header automatically, and the table roles are restored so screen readers still announce a table. An authored data-label on a cell overrides the derived one.
For wide tables that should keep their columns, wrap the table in a focusable scroll container labelled by its caption. Add data-table-scroll="block" to also cap the height.
Use data-sticky to keep headers or columns visible while scrolling.
Sticky Options
Value
Description
header
Keeps the table header row fixed at the top
column
Keeps the first column fixed on horizontal scroll
both
Both header and first column are sticky
Multiple Sticky Columns
Use data-sticky-column="n" to make the first n columns sticky.
Sticky headers and columns
1234567891011
<!-- Sticky header only --><tabledata-sticky="header">...</table><!-- Sticky first column --><tabledata-sticky="column">...</table><!-- Both sticky --><tabledata-sticky="both">...</table><!-- First 2 columns sticky --><tabledata-sticky="column"data-sticky-column="2">...</table>
Events
The component dispatches custom events for each interactive feature.
The component exposes methods for programmatic control.
Method
Parameters
Returns
Description
goToPage(n)
n: number
void
Navigate to a specific page (1-indexed, clamped to the valid range). No-op without data-paginate.
setFilter(query)
query: string
void
Programmatically set the filter text.
refresh()
-
void
Re-scan rows after adding or removing <tr> elements, then re-apply rollups, heatmaps, filtering, sorting, and pagination (the current page is kept when still valid).
getSelectedRows()
-
HTMLTableRowElement[]
Get array of currently selected rows.
Programmatic control
12345678910111213141516
const table = document.querySelector('data-table');// Navigate to page 3table.goToPage(3);// Filter by departmenttable.setFilter('engineering');// Refresh after external data changetable.refresh();// Get selected rows for bulk operationconst selected = table.getSelectedRows();selected.forEach(row => {console.log(row.cells[1].textContent); // Log names});
Property API (JS-first)
For reactive frameworks pushing live data, data-table exposes .rows and .columns alongside the markup-driven path. Existing <tr> nodes whose id persists across .rows assignments are preserved — selection, expansion, inline-edit state, focus, and CSS animations survive the diff.
Property
Type
Description
.rows
{ id, [colKey]: value, ... }[]
Setter runs a keyed diff against current <tr> children. id is the diff key; other fields populate cells per the column spec.
.columns
{ key, label, sort? }[]
Read-only: column spec derived from <thead> on upgrade. Each <th>'s data-keyattribute becomes the column key (falls back to lowercased text).
.renderRow
(row, columns) => Element
Optional custom row renderer. Default builds one <td> per column populated from row[col.key].
Set data-weight="N" on each criterion column header, data-rollup="weighted-sum" on a Score column, and data-heatmap for visual scanning. The component computes the score per row from the weighted criteria, sets data-sort-value so the Score column remains sortable, and tints cells low/mid/high based on relative value within the column.
This recipe replaces a dedicated decision-matrix component — there's no new element needed; the rule is "behaviour on existing element → data-*attribute".
Rollup kinds
sum — sum of all sibling numeric cells.
weighted-sum — each sibling cell × the data-weight on its column header.
product — multiply all sibling numeric cells (e.g. likelihood × impact for risk severity).
avg — average of all sibling numeric cells.
max — largest sibling numeric value.
Heatmap modes
high-good (also auto) — large values tinted green, small values red.
low-good — inverted; small values green (e.g. risk severity, defect count).
Tints use the --color-error-subtle, --color-warning-subtle, and --color-success-subtle tokens, which switch with the colour scheme; cell text stays --color-text so contrast holds in light and dark mode. Colour is never the only cue — the number stays in the cell.
Localizing the labels
The component generates some text of its own: the filter input's name and placeholder, the pagination buttons, and the messages it announces to screen readers. Each string has an English default and a data-label-*attribute on <data-table> that replaces it. Column headers, captions and cell content are your markup, so translate them there.
Announcement after filtering, when the total is one row
data-label-filtered-other
{count} of {total} rows shown
{count}, {total}
Announcement after filtering
data-label-all-one
All {total} row shown
{total}
Announcement when the filter is cleared, when the total is one row
data-label-all-other
All {total} rows shown
{total}
Announcement when the filter is cleared
data-label-selected-one
{count} row selected
{count}
Announcement when one row is selected
data-label-selected-other
{count} rows selected
{count}
Announcement after any other selection change
Things to know:
Placeholders. The component fills in the tokens in braces. Keep them in the translation and move them where the grammar needs them. {column} is the header text of the sorted column. {count} is the number of matching or selected rows and {total} is the number of rows in the table.
Plurals. The attributes ending in -one and -other are plural categories from Intl.PluralRules. A language with more categories can add -two, -few, -many or -zero. A category you leave out uses your -other text. The filter messages pick the category from {total}, and the selection messages pick it from {count}.
Numbers. Counts and page numbers are formatted with Intl.NumberFormat in the language of the nearest langattribute, so set lang on the component or the page.
Changes. The messages, the empty-state text and the pagination buttons read their attribute each time they are used, so a changed attribute applies from the next announcement or render. The filter input's name and placeholder and the pagination name are read once, when the component starts.
A table in Spanish
12345678910111213141516171819202122232425262728
<data-tablelang="es"data-label-filter="Filtrar las filas de la tabla"data-label-placeholder="Filtrar la tabla..."data-label-no-results="No se encontraron filas"data-label-pagination="Paginación de la tabla"data-label-prev="Anterior"data-label-next="Siguiente"data-label-sorted="Ordenado por {column}, en orden {direction}"data-label-ascending="ascendente"data-label-descending="descendente"data-label-filtered-one="Mostrando {count} de {total} fila"data-label-filtered-other="Mostrando {count} de {total} filas"data-label-all-one="Mostrando {total} fila"data-label-all-other="Mostrando las {total} filas"data-label-selected-one="{count} fila seleccionada"data-label-selected-other="{count} filas seleccionadas"><tabledata-filterabledata-paginate="10"><thead><tr><thdata-sort="string">Nombre</th><thdata-sort="number">Precio</th></tr></thead><tbody><!-- filas --></tbody></table></data-table>
The Translation guide covers the same pattern in other components.
Text for the visible empty state and the live-region announcement when the filter matches no rows.
data-label-filter
string
Filter table rows
Accessible name of the filter input.
data-label-placeholder
string
Filter table...
Placeholder of the filter input.
data-label-pagination
string
Table pagination
Accessible name of the pagination nav.
data-label-prev
string
Previous
Text of the previous-page button.
data-label-next
string
Next
Text of the next-page button.
data-label-sorted
string
Sorted by {column}, {direction}
Announcement after a sort. {column} is replaced by the header text and {direction} by the data-label-ascending or data-label-descending text.
data-label-ascending
string
ascending
Direction word used for {direction} in the sort announcement.
data-label-descending
string
descending
Direction word used for {direction} in the sort announcement.
data-label-filtered-one
string
{count} of {total} row shown
Announcement after filtering when Intl.PluralRules selects "one" for the total. {count} is replaced by the number of matching rows and {total} by the number of rows. Any category works: -two, -few, -many, -zero.
data-label-filtered-other
string
{count} of {total} rows shown
Announcement after filtering for the "other" category and the fallback for unset categories. {count} and {total} are replaced.
data-label-all-one
string
All {total} row shown
Announcement when the filter is cleared ("one" category). {total} is replaced by the number of rows; {count} holds the same number.
data-label-all-other
string
All {total} rows shown
Announcement when the filter is cleared ("other" category and fallback). {total} is replaced by the number of rows; {count} holds the same number.
data-label-selected-one
string
{count} row selected
Announcement after a selection change when Intl.PluralRules selects "one" for the count. {count} is replaced by the number of selected rows. Any category works: -two, -few, -many, -zero.
data-label-selected-other
string
{count} rows selected
Announcement after a selection change for the "other" category and the fallback for unset categories. {count} is replaced.
Required Structure
Element
Required
Description
<table>
yes
Standard HTML table — the component enhances it in place
Enable text search filtering (adds a search input above the table)
data-paginate
table
number
Enable pagination with N rows per page
data-sort
th
"string", "number", "date"
Enable sorting on this column with the specified comparator
data-weight
th
number
Column weight; multiplier applied to cell values for weighted-sum rollups
data-rollup
th
"sum", "weighted-sum", "product", "avg", "max"
Compute this column's cells from sibling cells in the same row
data-heatmap
th
"auto", "low-good", "high-good"
Tint this column's cells by relative value bucket (low/mid/high)
data-sort-value
td
string
Custom sort value overriding cell text. Use for formatted values, e.g. <td data-sort-value="1234">$1,234</td> — data-sort="number" parses the cell with parseFloat, so "$1,234" would sort as 0
data-filter-value
td
string
Custom filter value overriding cell text
data-expandable
tr
boolean
Mark row as expandable (followed by a data-expand-content row). Supply the toggle yourself: <button data-action="toggle-expand"> in a cell; the component manages aria-expanded
data-expand-content
tr
boolean
Hidden row revealed when its preceding expandable row is toggled
data-selectable
tr
boolean
Mark row as selectable via an author-supplied <input type="checkbox" data-action="select-row">; a thead checkbox with data-action="select-all" toggles all
CSS-Only Attributes
These attributes are handled by CSS styling, not JavaScript logic.
Everything interactive is a native control, so the table follows the normal tab order; there is no custom row navigation.
Key
Action
Tab / Shift+Tab
Move between the filter input, sort header buttons, checkboxes, expand toggles, and pagination buttons
Enter / Space
Sort by the focused column, toggle a checkbox, expand/collapse a row, or go to a page
After a pagination button is activated, focus moves to its replacement: Previous/Next keep focus (unless they become disabled), and a page number hands focus to the new current-page button.
ARIA and Semantics
aria-sort on sortable <th> headers reflects the current direction; the header's <button> is the control. The visual arrow is CSS content with empty alt text, so it is not read twice.
aria-expanded on data-action="toggle-expand" buttons reflects row expansion.
Row selection state is carried by the row checkboxes themselves.
aria-current="page" marks the current page; the pagination is a <nav aria-label="Table pagination">.
Screen Reader Announcements
A visually hidden role="status" region (aria-live="polite") inside the component announces:
Sort changes, e.g. “Sorted by Price, descending”
Filter results, e.g. “3 of 12 rows shown”, or the data-label-no-results text when nothing matches