Skip to content
Focsd homeFocsd homeFocsd
Forms

Table

A semantic data table with sortable columns.

  • Tag: focsd-table
  • Pattern: Table (sortable headers)
  • Category: Data

Example

HTML
<div class="full"><focsd-table id="table-demo" caption="Members"></focsd-table></div>
<script type="module">
const table = document.getElementById('table-demo');
table.columns = [
{ key: 'name', label: 'Name', sortable: true },
{ key: 'role', label: 'Role' },
{ key: 'projects', label: 'Projects', sortable: true, numeric: true },
];
table.rows = [
{ name: 'Lukas Brandt', role: 'Editor', projects: 8 },
{ name: 'Amara Okafor', role: 'Owner', projects: 12 },
{ name: 'Priya Raman', role: 'Editor', projects: 5 },
];
</script>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-table.js';
</script>
<focsd-table caption="Members"></focsd-table>

API

Attributes

AttributePropertyTypeDefault
captioncaptionstring—
sort-keysortKeystring—
sort-directionsortDirectionSortDirectionnone

JavaScript properties

PropertyTypeDescription
columns{ key: string, label: string, sortable?: boolean, numeric?: boolean }[]Column definitions. Numeric columns are end-aligned in tabular figures.
rowsobject[]Row objects keyed by column key.

CSS parts

Style the inside of the component with ::part(), for example focsd-table::part(caption).

PartDescription
captionThe caption element.
cellThe cell element.
headerThe header element.
numericAdded to header and cells of numeric columns.
sortThe sort button in a sortable column header.
sort-iconThe sort direction arrow.
tableThe table element.
viewportThe viewport element.

Accessibility

  • A native <table> with <caption> and th scope="col"; sortable headers contain a button and the th carries aria-sort.
  • The wrapper is a labeled scroll region that becomes focusable when the table overflows, so wide tables can be scrolled with the keyboard.