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? }. type is 'string' or 'number' for sort order.
  • data (array, required) β€” Row data: array of objects with keys matching column key.
  • 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
Sample data
AliceDeveloperActive
BobDesignerActive
CarolManagerAway

With sorting (number column)

Set type: 'number' on columns that should sort numerically.

Live example
Scores
Alice923
Bob872
Carol954

With filter

Use filterable to show a search input that filters rows by any column.

Live example
Filterable list
AliceDeveloperActive
BobDesignerActive
CarolManagerAway
DaveDeveloperActive

Without stripes

Live example
Plain table
12
34

Features

  • Accessible β€” Semantic table, caption, scope="col", aria-sort on 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' },
  ]}
/>

Astro & Vanilla: Astro Β· Vanilla