Table β Svelte
Table component β Svelte.
Table component
An accessible data table for displaying tabular data. Supports column header sorting (click or Enter/Space), optional filter input to search across all columns, striped rows, and responsive horizontal scroll. Same styles and functionality as the Astro Table.
Props
columns(array, required) β Column definitions:{ key, label, sortable?, type? }.typeis'string'or'number'for sort order.data(array, required) β Row data: array of objects with keys matching columnkey.caption(string, optional) β Table caption for accessibility.sortable(boolean, optional) β Enable column header sorting (default: true).filterable(boolean, optional) β Show filter input above table (default: false).filterPlaceholder(string, optional) β Placeholder for filter input (default: "Filter tableβ¦").striped(boolean, optional) β Striped rows (default: true).class(string, optional) β Additional CSS classes.
Basic usage
Live example
| Alice | Developer | Active |
| Bob | Designer | Active |
| Carol | Manager | Away |
With sorting (number column)
Set type: 'number' on columns that should sort numerically.
Live example
| Alice | 92 | 3 |
| Bob | 87 | 2 |
| Carol | 95 | 4 |
With filter
Use filterable to show a search input that filters rows by any column.
Live example
| Alice | Developer | Active |
| Bob | Designer | Active |
| Carol | Manager | Away |
| Dave | Developer | Active |
Without stripes
Live example
| 1 | 2 |
| 3 | 4 |
Features
- Accessible β Semantic table, caption,
scope="col",aria-sorton sortable headers, keyboard (Enter/Space) to sort. - Sorting β Sortable column headers with Sort icon; click to sort ascending/descending;
type: 'number'for numeric sort. - Filtering β Optional filter input with Filter icon; rows shown/hidden by matching text in any cell.
- Striped rows β Optional alternating row background (default: true).
- Responsive β Table wrapper scrolls horizontally on small screens.
Usage
svelte svelte
<script>
import Table from './Table.svelte';
</script>
<Table
caption="Sample data"
columns={[
{ key: 'name', label: 'Name' },
{ key: 'role', label: 'Role' },
{ key: 'status', label: 'Status' },
]}
data={[
{ name: 'Alice', role: 'Developer', status: 'Active' },
{ name: 'Bob', role: 'Designer', status: 'Active' },
{ name: 'Carol', role: 'Manager', status: 'Away' },
]}
/>