Table
A semantic data table with sortable columns.
Example
<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>import { Table } from '@focsd-dev/react';
export function Example() { return <Table caption="Members"></Table>;}<script setup>import '@focsd-dev/components/focsd-table.js';</script>
<template> <focsd-table caption="Members"></focsd-table></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-table.js';
// template<focsd-table caption="Members"></focsd-table><script> import '@focsd-dev/components/focsd-table.js';</script>
<focsd-table caption="Members"></focsd-table>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
caption | caption | string | — |
sort-key | sortKey | string | — |
sort-direction | sortDirection | SortDirection | none |
JavaScript properties
| Property | Type | Description |
|---|---|---|
columns | { key: string, label: string, sortable?: boolean, numeric?: boolean }[] | Column definitions. Numeric columns are end-aligned in tabular figures. |
rows | object[] | Row objects keyed by column key. |
CSS parts
Style the inside of the component with ::part(), for example focsd-table::part(caption).
| Part | Description |
|---|---|
caption | The caption element. |
cell | The cell element. |
header | The header element. |
numeric | Added to header and cells of numeric columns. |
sort | The sort button in a sortable column header. |
sort-icon | The sort direction arrow. |
table | The table element. |
viewport | The viewport element. |
Accessibility
- A native
<table>with<caption>andth scope="col"; sortable headers contain a button and thethcarriesaria-sort. - The wrapper is a labeled scroll region that becomes focusable when the table overflows, so wide tables can be scrolled with the keyboard.
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.