Skip to content
Likable Aurora @likable-hair/svelte 5

Table

Table of rows and columns. columns declares what each column shows (key, label, a type that formats numbers, dates and yes/no with Intl in the language of locale, format, or a cell snippet) and rows are plain objects, identified by rowKey. Sortable columns sort the rows on their own (ascending, descending, unsorted), or only report the new sort with sorting="manual" when the server sorts. selectable adds a checkbox per row (shift-click selects a range), expandedSnippet a detail row under each row, actionsSnippet a column of buttons that stays on the right while scrolling (with actionsVisibility="hover" it shows only on hover and focus). rowHref turns every row into a link (Ctrl-click and middle click open it in a new tab), onrowclick makes rows clickable and focusable. pinned columns stay on the left (unless together with the checkboxes and the actions they would take more than half of the table), resizable columns can be dragged or resized with the arrow keys, and columnState keeps order, visibility, widths and pins as plain data to save. Empty cells show "—". When the table is narrower than cardBreakpoint (640px by default) every row becomes a card, with the cardColumns (the first 4 by default) and the other columns behind "Show more fields". Above virtualize rows (200 by default) only the rows in view are in the page, so thousands of rows stay fast. onendreached is called when the last rows come into view, for loading more. While loading the table shows a progress bar, or placeholder rows when it has none; with no rows it shows NoData. State is exposed as data-cards, data-loading, data-disabled, data-resizing, data-actions-visibility and data-pins-off on the root, and data-selected, data-expanded on rows for app CSS.

import { Table } from '@likable-hair/svelte';

src/lib/components/simple/tables/Table.svelte · Markdown for LLMs

Basic table

columns declares what each column shows and rows are plain objects with an id. A number column is right-aligned, with monospaced digits formatted by Intl.NumberFormat; a cell snippet draws anything else, here a chip. Sortable headers sort the rows: ascending, descending, then back to the original order.

Products
Nourishing shampoo 42 €14.90
Keratin mask 4 €22.50
Argan oil 0 €18.00
Volume mousse 17 €12.40
Code
<script lang="ts">
	import { Chip, Table, type TableColumn } from '@likable-hair/svelte';

	type Product = { id: number; name: string; stock: number; price: number };

	const rows: Product[] = [
		{ id: 1, name: 'Nourishing shampoo', stock: 42, price: 14.9 },
		{ id: 2, name: 'Keratin mask', stock: 4, price: 22.5 },
		{ id: 3, name: 'Argan oil', stock: 0, price: 18 },
		{ id: 4, name: 'Volume mousse', stock: 17, price: 12.4 }
	];

	const columns: TableColumn<Product>[] = [
		{ key: 'name', label: 'Product', sortable: true },
		{ key: 'stock', label: 'Stock', sortable: true, cell: stock },
		{
			key: 'price',
			label: 'Price',
			type: 'number',
			numberFormat: { style: 'currency', currency: 'EUR' },
			sortable: true
		}
	];
</script>

{#snippet stock({ value }: { value: number })}
	<Chip size="sm" variant={value === 0 ? 'error' : value < 10 ? 'warning' : 'success'}>{value}</Chip>
{/snippet}

<Table {rows} {columns} caption="Products" />

Column types

type formats the value with Intl, in the language of locale: date and datetime take a Date, an ISO string, a timestamp or a luxon DateTime, number takes the options of Intl.NumberFormat, boolean shows a check mark for true. format writes the text by hand. Empty values show "—", or the empty text of the column.

Client
Day
Booked on
Duration
Paid
Notes
Luca Rossi Thu, Sep 24 09/20/2026, 09:30 AM 45 min Yes Prefers the morning
Giulia Marini Fri, Sep 25 09/21/2026, 04:05 PM 120 min No No notes
Sara Bianchi Sat, Sep 26 09/22/2026, 11:40 AM 30 min Yes No notes
Code
<script lang="ts">
	import { Table, type TableColumn } from '@likable-hair/svelte';

	type Visit = {
		id: number;
		client: string;
		day: Date;
		booked: string;
		minutes: number;
		paid: boolean;
		notes: string | null;
	};

	const rows: Visit[] = [
		{
			id: 1,
			client: 'Luca Rossi',
			day: new Date(2026, 8, 24),
			booked: '2026-09-20T09:30:00',
			minutes: 45,
			paid: true,
			notes: 'Prefers the morning'
		},
		{
			id: 2,
			client: 'Giulia Marini',
			day: new Date(2026, 8, 25),
			booked: '2026-09-21T16:05:00',
			minutes: 120,
			paid: false,
			notes: null
		},
		{
			id: 3,
			client: 'Sara Bianchi',
			day: new Date(2026, 8, 26),
			booked: '2026-09-22T11:40:00',
			minutes: 30,
			paid: true,
			notes: ''
		}
	];

	const columns: TableColumn<Visit>[] = [
		{ key: 'client', label: 'Client' },
		{ key: 'day', label: 'Day', type: 'date', dateFormat: { weekday: 'short', day: 'numeric', month: 'short' } },
		{ key: 'booked', label: 'Booked on', type: 'datetime' },
		{ key: 'minutes', label: 'Duration', type: 'number', format: (value) => `${value} min` },
		{ key: 'paid', label: 'Paid', type: 'boolean', align: 'center' },
		{ key: 'notes', label: 'Notes', empty: 'No notes' }
	];
</script>

<Table {rows} {columns} />

Selection and row actions

selectable="multiple" adds a checkbox to each row and "select all" in the header; shift-click selects a range. bind:selected holds the selected rows. actionsSnippet puts buttons in a column that stays on the right while the table scrolls; actionsVisibility="hover" shows them only on the row under the pointer or with the focus, for dense tables.

Service
Status
Amount
Actions
LRLuca Rossi Cut and beard 09/24/2026, 09:30 AM Confirmed €42.00
GMGiulia Marini Balayage 09/24/2026, 11:00 AM Pending €120.00
SBSara Bianchi Blow-dry 09/24/2026, 03:15 PM Cancelled €25.00
MNMarco Neri Cut 09/24/2026, 05:00 PM Confirmed €28.00

1 selected: Luca Rossi

Code
<script lang="ts">
	import { mdiDotsVertical, mdiPencilOutline } from '@mdi/js';
	import { Button, Chip, Table, type TableColumn } from '@likable-hair/svelte';

	type Booking = {
		id: number;
		client: string;
		initials: string;
		service: string;
		start: Date;
		status: 'confirmed' | 'pending' | 'cancelled';
		amount: number;
	};

	const rows: Booking[] = [
		{ id: 1, client: 'Luca Rossi', initials: 'LR', service: 'Cut and beard', start: new Date(2026, 8, 24, 9, 30), status: 'confirmed', amount: 42 },
		{ id: 2, client: 'Giulia Marini', initials: 'GM', service: 'Balayage', start: new Date(2026, 8, 24, 11), status: 'pending', amount: 120 },
		{ id: 3, client: 'Sara Bianchi', initials: 'SB', service: 'Blow-dry', start: new Date(2026, 8, 24, 15, 15), status: 'cancelled', amount: 25 },
		{ id: 4, client: 'Marco Neri', initials: 'MN', service: 'Cut', start: new Date(2026, 8, 24, 17), status: 'confirmed', amount: 28 }
	];

	const statuses = {
		confirmed: { label: 'Confirmed', variant: 'success' },
		pending: { label: 'Pending', variant: 'warning' },
		cancelled: { label: 'Cancelled', variant: 'error' }
	} as const;

	const columns: TableColumn<Booking>[] = [
		{ key: 'client', label: 'Client', sortable: true, cell: client },
		{ key: 'service', label: 'Service' },
		{ key: 'start', label: 'Date', type: 'datetime', sortable: true },
		{ key: 'status', label: 'Status', cell: status },
		{ key: 'amount', label: 'Amount', type: 'number', numberFormat: { style: 'currency', currency: 'EUR' } }
	];

	let selected = $state<Booking[]>([rows[0]]);
</script>

{#snippet client({ row }: { row: Booking })}
	<span class="who"><span class="avatar">{row.initials}</span>{row.client}</span>
{/snippet}

{#snippet status({ row }: { row: Booking })}
	<Chip size="sm" variant={statuses[row.status].variant}>{statuses[row.status].label}</Chip>
{/snippet}

{#snippet actions({ row }: { row: Booking })}
	<Button buttonType="icon" variant="secondary" size="sm" icon={mdiPencilOutline} aria-label="Edit {row.client}" />
	<Button buttonType="icon" variant="secondary" size="sm" icon={mdiDotsVertical} aria-label="More for {row.client}" />
{/snippet}

<div class="stack">
	<Table {rows} {columns} selectable="multiple" bind:selected actionsSnippet={actions} />
	<p>{selected.length} selected: {selected.map((row) => row.client).join(', ') || 'none'}</p>
</div>

<style>
	.stack {
		display: flex;
		width: 100%;
		flex-direction: column;
		gap: 12px;
	}

	.who {
		display: inline-flex;
		align-items: center;
		gap: 10px;
	}

	.avatar {
		display: inline-grid;
		place-items: center;
		width: 28px;
		height: 28px;
		border-radius: 50%;
		background: var(--global-color-primary-soft);
		color: var(--global-color-primary);
		font-size: 11px;
		font-weight: 600;
	}

	p {
		margin: 0;
		color: var(--global-color-text-2);
		font-size: 13px;
	}
</style>

Expandable rows

expandedSnippet adds a button that opens a detail row under the row; expandable chooses which rows have one. bind:expanded holds the keys of the open rows. A nested Table inside the snippet shows sub-rows.

Show details
Client
Visits
Luca Rossi 12
Allergic to PPD: use the ammonia-free line. Last colour 6.3.
Giulia Marini 4
Sara Bianchi 7
Code
<script lang="ts">
	import { Table, type TableColumn } from '@likable-hair/svelte';

	type Client = { id: number; name: string; visits: number; notes?: string };

	const rows: Client[] = [
		{ id: 1, name: 'Luca Rossi', visits: 12, notes: 'Allergic to PPD: use the ammonia-free line. Last colour 6.3.' },
		{ id: 2, name: 'Giulia Marini', visits: 4 },
		{ id: 3, name: 'Sara Bianchi', visits: 7, notes: 'Likes short appointments, books online.' }
	];

	const columns: TableColumn<Client>[] = [
		{ key: 'name', label: 'Client' },
		{ key: 'visits', label: 'Visits', type: 'number' }
	];

	let expanded = $state<(string | number)[]>([1]);
</script>

{#snippet detail({ row }: { row: Client })}
	{row.notes}
{/snippet}

<Table {rows} {columns} expandedSnippet={detail} expandable={(row) => !!row.notes} bind:expanded />

Pinned and resizable columns

pinned columns stay on the left while the table scrolls sideways, and are moved before the others. With resizable the edge of each header can be dragged, or moved with the arrow keys when it has the focus (Shift for bigger steps). bind:columnState holds order, visibility, widths and pins as plain data, ready to be saved; columnsKey saves it in the browser instead. cardBreakpoint={false} keeps the table on narrow screens.

Operator
Mon
Tue
Wed
Thu
Fri
Sat
Sun
Giulia 6 8 10 1 3 5 7
Luca 9 1 4 7 10 2 5
Sara 1 5 9 2 6 10 3
Marco 4 9 3 8 2 7 1
"not changed yet"
Code
<script lang="ts">
	import { Table, type TableColumn, type TableColumnState } from '@likable-hair/svelte';

	type Shift = { id: number; name: string; [day: string]: number | string };

	const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
	const rows: Shift[] = ['Giulia', 'Luca', 'Sara', 'Marco'].map((name, index) => ({
		id: index + 1,
		name,
		...Object.fromEntries(days.map((day, position) => [day, ((index + 2) * (position + 3)) % 11]))
	}));

	const columns: TableColumn<Shift>[] = [
		{ key: 'name', label: 'Operator', pinned: true, minWidth: '120px' },
		...days.map((day): TableColumn<Shift> => ({ key: day, label: day, type: 'number', minWidth: '110px' }))
	];

	let columnState = $state<TableColumnState[]>();
</script>

<div class="stack">
	<Table {rows} {columns} resizable bind:columnState cardBreakpoint={false} />
	<code>{JSON.stringify(columnState?.filter((column) => column.width) ?? 'not changed yet')}</code>
</div>

<style>
	.stack {
		display: flex;
		width: 100%;
		flex-direction: column;
		gap: 12px;
		max-width: 560px;
	}

	code {
		color: var(--global-color-text-2);
		font-family: var(--global-font-family-mono);
		font-size: 12px;
		overflow-wrap: anywhere;
	}
</style>

Loading and no data

While loading the table shows a progress bar under the header and dims the rows, or placeholder rows when it has none yet (loadingRows). Without rows it shows NoData, with noDataTitle or noDataSnippet.

Product
Price
Nourishing shampoo €14.90
Keratin mask €22.50
Code
<script lang="ts">
	import { Switch, Table, type TableColumn } from '@likable-hair/svelte';

	type Product = { id: number; name: string; price: number };

	const all: Product[] = [
		{ id: 1, name: 'Nourishing shampoo', price: 14.9 },
		{ id: 2, name: 'Keratin mask', price: 22.5 }
	];

	const columns: TableColumn<Product>[] = [
		{ key: 'name', label: 'Product' },
		{ key: 'price', label: 'Price', type: 'number', numberFormat: { style: 'currency', currency: 'EUR' } }
	];

	let loading = $state(false);
	let empty = $state(false);
</script>

<div class="stack">
	<div class="controls">
		<Switch bind:checked={loading} label="Loading" />
		<Switch bind:checked={empty} label="No rows" />
	</div>
	<Table rows={empty ? [] : all} {columns} {loading} loadingRows={2} noDataTitle="No products yet" />
</div>

<style>
	.stack {
		display: flex;
		width: 100%;
		flex-direction: column;
		gap: 12px;
	}

	.controls {
		display: flex;
		gap: 24px;
	}
</style>

Cards on narrow screens

When the table is narrower than cardBreakpoint (640px by default, measured on the table, not on the screen) every row becomes a card: the cardTitle column on top with the checkbox and the actions, the other columns as label and value, and the sorting in a select above. cardBreakpoint={false} keeps the table, which then scrolls sideways.

Service
Status
Amount
Actions
Luca Rossi Cut and beard 09/24/2026, 09:30 AM Confirmed €42.00
Giulia Marini Balayage 09/24/2026, 11:00 AM Pending €120.00
Code
<script lang="ts">
	import { mdiPencilOutline } from '@mdi/js';
	import { Button, Chip, Table, type TableColumn } from '@likable-hair/svelte';

	type Booking = { id: number; client: string; service: string; start: Date; status: string; amount: number };

	const rows: Booking[] = [
		{ id: 1, client: 'Luca Rossi', service: 'Cut and beard', start: new Date(2026, 8, 24, 9, 30), status: 'Confirmed', amount: 42 },
		{ id: 2, client: 'Giulia Marini', service: 'Balayage', start: new Date(2026, 8, 24, 11), status: 'Pending', amount: 120 }
	];

	const columns: TableColumn<Booking>[] = [
		{ key: 'client', label: 'Client', sortable: true },
		{ key: 'service', label: 'Service' },
		{ key: 'start', label: 'Date', type: 'datetime', sortable: true },
		{ key: 'status', label: 'Status', cell: status },
		{ key: 'amount', label: 'Amount', type: 'number', numberFormat: { style: 'currency', currency: 'EUR' } }
	];

	let selected = $state<Booking[]>([]);
</script>

{#snippet status({ value }: { value: string })}
	<Chip size="sm" variant={value === 'Confirmed' ? 'success' : 'warning'}>{value}</Chip>
{/snippet}

{#snippet actions({ row }: { row: Booking })}
	<Button buttonType="icon" variant="secondary" size="sm" icon={mdiPencilOutline} aria-label="Edit {row.client}" />
{/snippet}

<div class="phone">
	<Table {rows} {columns} selectable="multiple" bind:selected actionsSnippet={actions} />
</div>

<style>
	.phone {
		width: 100%;
		max-width: 360px;
	}
</style>

Many columns in cards

With many columns a card shows the title and a few fields, and the others behind "Show more fields". cardColumns picks the fields that stay visible, here the contact details, the last visit and the status; without it the card shows the first 4 columns after the title. In cards a false yes/no reads "No".

Code
Email
Phone
Province
Country
VAT number
Fiscal code
Total spent
Average ticket
Loyalty points
Newsletter
Marketing consent
Status
Operator
Notes
Actions
Luca Rossi CL-00231 luca.rossi@example.com +39 333 123 4567 Milan MI Italy IT01234567890 RSSLCU85M01F205X 03/14/2024 09/24/2026, 09:30 AM 37 €1,842.50 €49.80 1,240 Yes No Active Giulia Prefers mornings
Giulia Marini CL-00232 giulia.marini@example.com +39 347 765 4321 Turin TO Italy — MRNGLI90A41L219K 11/02/2025 09/20/2026, 04:00 PM 8 €960.00 €120.00 310 No Yes New Luca —
Code
<script lang="ts">
	import { mdiDotsVertical, mdiPencilOutline } from '@mdi/js';
	import { Button, Chip, Table, type TableColumn } from '@likable-hair/svelte';

	type Client = {
		id: number;
		code: string;
		name: string;
		email: string;
		phone: string;
		city: string;
		province: string;
		country: string;
		vat: string | null;
		fiscalCode: string;
		created: Date;
		lastVisit: Date;
		visits: number;
		spent: number;
		ticket: number;
		points: number;
		newsletter: boolean;
		marketing: boolean;
		status: 'Active' | 'New';
		operator: string;
		notes: string | null;
	};

	const rows: Client[] = [
		{
			id: 1,
			code: 'CL-00231',
			name: 'Luca Rossi',
			email: 'luca.rossi@example.com',
			phone: '+39 333 123 4567',
			city: 'Milan',
			province: 'MI',
			country: 'Italy',
			vat: 'IT01234567890',
			fiscalCode: 'RSSLCU85M01F205X',
			created: new Date(2024, 2, 14),
			lastVisit: new Date(2026, 8, 24, 9, 30),
			visits: 37,
			spent: 1842.5,
			ticket: 49.8,
			points: 1240,
			newsletter: true,
			marketing: false,
			status: 'Active',
			operator: 'Giulia',
			notes: 'Prefers mornings'
		},
		{
			id: 2,
			code: 'CL-00232',
			name: 'Giulia Marini',
			email: 'giulia.marini@example.com',
			phone: '+39 347 765 4321',
			city: 'Turin',
			province: 'TO',
			country: 'Italy',
			vat: null,
			fiscalCode: 'MRNGLI90A41L219K',
			created: new Date(2025, 10, 2),
			lastVisit: new Date(2026, 8, 20, 16),
			visits: 8,
			spent: 960,
			ticket: 120,
			points: 310,
			newsletter: false,
			marketing: true,
			status: 'New',
			operator: 'Luca',
			notes: null
		}
	];

	const euro: Intl.NumberFormatOptions = { style: 'currency', currency: 'EUR' };

	const columns: TableColumn<Client>[] = [
		{ key: 'name', label: 'Client', sortable: true },
		{ key: 'code', label: 'Code' },
		{ key: 'email', label: 'Email' },
		{ key: 'phone', label: 'Phone' },
		{ key: 'city', label: 'City', sortable: true },
		{ key: 'province', label: 'Province' },
		{ key: 'country', label: 'Country' },
		{ key: 'vat', label: 'VAT number' },
		{ key: 'fiscalCode', label: 'Fiscal code' },
		{ key: 'created', label: 'Client since', type: 'date', sortable: true },
		{ key: 'lastVisit', label: 'Last visit', type: 'datetime', sortable: true },
		{ key: 'visits', label: 'Visits', type: 'number', sortable: true },
		{ key: 'spent', label: 'Total spent', type: 'number', numberFormat: euro },
		{ key: 'ticket', label: 'Average ticket', type: 'number', numberFormat: euro },
		{ key: 'points', label: 'Loyalty points', type: 'number' },
		{ key: 'newsletter', label: 'Newsletter', type: 'boolean' },
		{ key: 'marketing', label: 'Marketing consent', type: 'boolean' },
		{ key: 'status', label: 'Status', cell: status },
		{ key: 'operator', label: 'Operator' },
		{ key: 'notes', label: 'Notes' }
	];
</script>

{#snippet status({ value }: { value: Client['status'] })}
	<Chip size="sm" variant={value === 'Active' ? 'success' : 'primary'}>{value}</Chip>
{/snippet}

{#snippet actions({ row }: { row: Client })}
	<Button buttonType="icon" variant="secondary" size="sm" icon={mdiPencilOutline} aria-label="Edit {row.name}" />
	<Button buttonType="icon" variant="secondary" size="sm" icon={mdiDotsVertical} aria-label="More for {row.name}" />
{/snippet}

<div class="phone">
	<Table
		{rows}
		{columns}
		selectable="multiple"
		actionsSnippet={actions}
		cardColumns={['email', 'phone', 'lastVisit', 'status']}
	/>
</div>

<style>
	.phone {
		width: 100%;
		max-width: 360px;
	}
</style>

Sorting on the server

With sorting="manual" the table does not reorder the rows: it updates sort and calls onsortchange, and the app loads the rows in the new order, here with a fake request. DataTable does this for you, with the pages, the search and the filters in one query.

Milan 1,371,000
Naples 913,000
Turin 841,000
Rome 2,749,000
Code
<script lang="ts">
	import { Table, type TableColumn, type TableSort } from '@likable-hair/svelte';

	type City = { id: number; name: string; population: number };

	const all: City[] = [
		{ id: 1, name: 'Milan', population: 1371000 },
		{ id: 2, name: 'Naples', population: 913000 },
		{ id: 3, name: 'Turin', population: 841000 },
		{ id: 4, name: 'Rome', population: 2749000 }
	];

	const columns: TableColumn<City>[] = [
		{ key: 'name', label: 'City', sortable: true },
		{ key: 'population', label: 'Population', type: 'number', sortable: true }
	];

	let rows = $state(all);
	let sort = $state<TableSort>();
	let loading = $state(false);

	async function load(next: TableSort | undefined) {
		loading = true;
		await new Promise((resolve) => setTimeout(resolve, 600));
		const sign = next?.direction === 'desc' ? -1 : 1;
		rows = next
			? [...all].sort((a, b) =>
					next.key === 'name' ? sign * a.name.localeCompare(b.name) : sign * (a.population - b.population)
				)
			: all;
		loading = false;
	}
</script>

<Table {rows} {columns} sorting="manual" bind:sort {loading} onsortchange={(event) => load(event.sort)} />

Custom style

Every part has a CSS variable: here a compact table with a tinted header, normal-case labels and taller rows on hover. The variables also apply to the cards.

Product
Stock
Price
Nourishing shampoo 42 €14.90
Keratin mask 4 €22.50
Argan oil 0 €18.00
Code
<script lang="ts">
	import { Table, type TableColumn } from '@likable-hair/svelte';

	type Product = { id: number; name: string; stock: number; price: number };

	const rows: Product[] = [
		{ id: 1, name: 'Nourishing shampoo', stock: 42, price: 14.9 },
		{ id: 2, name: 'Keratin mask', stock: 4, price: 22.5 },
		{ id: 3, name: 'Argan oil', stock: 0, price: 18 }
	];

	const columns: TableColumn<Product>[] = [
		{ key: 'name', label: 'Product' },
		{ key: 'stock', label: 'Stock', type: 'number' },
		{ key: 'price', label: 'Price', type: 'number', numberFormat: { style: 'currency', currency: 'EUR' } }
	];
</script>

<Table
	{rows}
	{columns}
	--table-header-background="var(--global-color-primary-soft)"
	--table-header-color="var(--global-color-primary)"
	--table-header-text-transform="none"
	--table-header-font-size="13px"
	--table-header-letter-spacing="0"
	--table-cell-padding="6px 12px"
	--table-border-radius="var(--global-radius-sm)"
	--table-row-hover-background="var(--global-color-accent-soft)"
/>

Thousands of rows

Above virtualize rows (200 by default) only the rows in view, plus a margin, are in the page: here 10,000 rows scroll inside the table (--table-max-height), and they would scroll with the page the same way. The columns keep the widths of the first rows. virtualize={false} puts every row in the page, for example to let the browser find text in all of them.

Stock movements
Code
Warehouse
Quantity
Date
MV-00001 Milan -120 09/01/2026, 08:00 AM
MV-00002 Turin -83 09/02/2026, 09:00 AM
MV-00003 Bologna -46 09/03/2026, 10:00 AM
MV-00004 Naples -9 09/04/2026, 11:00 AM
MV-00005 Milan 28 09/05/2026, 12:00 PM
MV-00006 Turin 65 09/06/2026, 01:00 PM
MV-00007 Bologna 102 09/07/2026, 02:00 PM
MV-00008 Naples 139 09/08/2026, 03:00 PM
MV-00009 Milan 176 09/09/2026, 04:00 PM
MV-00010 Turin 213 09/10/2026, 05:00 PM
MV-00011 Bologna 250 09/11/2026, 08:00 AM
MV-00012 Naples 287 09/12/2026, 09:00 AM
MV-00013 Milan 324 09/13/2026, 10:00 AM
MV-00014 Turin 361 09/14/2026, 11:00 AM
MV-00015 Bologna -102 09/15/2026, 12:00 PM
MV-00016 Naples -65 09/16/2026, 01:00 PM
MV-00017 Milan -28 09/17/2026, 02:00 PM
MV-00018 Turin 9 09/18/2026, 03:00 PM
MV-00019 Bologna 46 09/19/2026, 04:00 PM
MV-00020 Naples 83 09/20/2026, 05:00 PM
MV-00021 Milan 120 09/21/2026, 08:00 AM
MV-00022 Turin 157 09/22/2026, 09:00 AM
MV-00023 Bologna 194 09/23/2026, 10:00 AM
MV-00024 Naples 231 09/24/2026, 11:00 AM
MV-00025 Milan 268 09/25/2026, 12:00 PM
MV-00026 Turin 305 09/26/2026, 01:00 PM
MV-00027 Bologna 342 09/27/2026, 02:00 PM
MV-00028 Naples 379 09/28/2026, 03:00 PM
MV-00029 Milan -84 09/29/2026, 04:00 PM
MV-00030 Turin -47 09/30/2026, 05:00 PM
MV-00031 Bologna -10 09/01/2026, 08:00 AM
MV-00032 Naples 27 09/02/2026, 09:00 AM
MV-00033 Milan 64 09/03/2026, 10:00 AM
MV-00034 Turin 101 09/04/2026, 11:00 AM
MV-00035 Bologna 138 09/05/2026, 12:00 PM
MV-00036 Naples 175 09/06/2026, 01:00 PM
MV-00037 Milan 212 09/07/2026, 02:00 PM
MV-00038 Turin 249 09/08/2026, 03:00 PM
MV-00039 Bologna 286 09/09/2026, 04:00 PM
MV-00040 Naples 323 09/10/2026, 05:00 PM
Code
<script lang="ts">
	import { Table, type TableColumn } from '@likable-hair/svelte';

	type Movement = { id: number; code: string; warehouse: string; quantity: number; date: Date };

	const warehouses = ['Milan', 'Turin', 'Bologna', 'Naples'];

	const rows: Movement[] = Array.from({ length: 10000 }, (_, index) => ({
		id: index + 1,
		code: `MV-${String(index + 1).padStart(5, '0')}`,
		warehouse: warehouses[index % warehouses.length],
		quantity: ((index * 37) % 500) - 120,
		date: new Date(2026, 8, 1 + (index % 30), 8 + (index % 10))
	}));

	const columns: TableColumn<Movement>[] = [
		{ key: 'code', label: 'Code' },
		{ key: 'warehouse', label: 'Warehouse' },
		{ key: 'quantity', label: 'Quantity', type: 'number' },
		{ key: 'date', label: 'Date', type: 'datetime' }
	];
</script>

<Table --table-max-height="360px" caption="Stock movements" {rows} {columns} selectable="multiple" />

Props

NameTypeDefaultDescription
rows Row[][]The rows, plain objects.
columns requiredTableColumn<Row>[]The columns, in their default order (see TableColumn).
rowKey string | ((row: Row) => string | number)'id'Identity of a row: the name of a property or a function. Used as the key of the list, of the selection and of the expanded rows.
sort bindable TableSortCurrent sorting, or empty for the order of rows.
sorting 'local' | 'manual''local'local: the table sorts the rows it has. manual: it only updates sort and calls onsortchange, and the app passes the rows already sorted (for example by the server).
selectable 'single' | 'multiple'Adds a checkbox to each row: multiple also adds "select all" in the header and selects a range with shift-click, single keeps at most one row selected.
selected bindable Row[]Selected rows, compared through rowKey.
selectedAll bindable booleanEvery row is selected, also those not loaded (for example on other pages), except excluded. Set by the app or by DataTable; the header checkbox of the table selects only the rows it shows.
excluded bindable Row[]Rows left out of selectedAll.
expanded bindable (string | number)[]Keys (rowKey) of the expanded rows.
expandable (row: Row) => booleanWhich rows can expand. Defaults to all of them when expandedSnippet is set.
rowHref (row: Row) => string | undefinedURL of a row: the row becomes a link, with a real link inside for the keyboard and screen readers. Ctrl-click and middle click open it in a new tab.
rowClass (row: Row) => ClassValueExtra classes of a row.
empty string'—'Text of empty cells (null, undefined, empty string) of every column, unless the column sets its own.
loading booleanfalseShows that the rows are loading: a progress bar under the header, or loadingRows placeholder rows when there are no rows yet.
loadingRows number5Number of placeholder rows while loading without rows.
noDataTitle stringTitle shown when there are no rows. Defaults to the one of NoData, in the language of locale.
columnState bindable TableColumnState[]Order, visibility, width and pin of the columns, in display order: plain data to save and restore. Columns missing from it keep their defaults, unknown keys are ignored.
columnsKey stringSaves columnState in the browser (localStorage) under this key and restores it on load, when the app does not pass its own.
resizable booleanfalseColumns can be resized by dragging the edge of their header, or with the arrow keys when it has the focus.
actionsVisibility 'always' | 'hover''always'always shows the buttons of actionsSnippet on every row; hover only on the row under the pointer or with the focus inside, for dense tables (always on touch screens and in the cards).
cardBreakpoint number | false640Below this width of the table, in pixels, every row is shown as a card. false keeps the table, which scrolls sideways.
cardTitle stringKey of the column used as the title of the cards and as the name of the rows for screen readers. Defaults to the first visible column.
cardColumns string[]Keys of the columns always shown in the cards, under the title; the other columns are behind a "Show more fields" button in each card. Defaults to the first 4 visible columns after the title.
caption stringAccessible name of the table, read by screen readers.
locale stringBCP 47 locale of the texts and of the formatting of numbers and dates: it and en texts are built in, other languages fall back to English. Defaults to the one set with setDefaultLocale, else en.
labels { selectAll?: string; selectAllShort?: string; selectRow?: string; row?: string; expand?: string; collapse?: string; actions?: string; resize?: string; info?: string; open?: string; loading?: string; yes?: string; no?: string; sortBy?: string; unsorted?: string; moreFields?: string; fewerFields?: string; ascending?: string; descending?: string; }Texts to change, on top of those of locale. {row}, {index} and {column} are replaced by the name of the row, its position and the label of the column.
class { container?: ClassValue; table?: ClassValue; header?: ClassValue; row?: ClassValue; cell?: ClassValue; }{}Classes of the parts: container the root, table the <table>, header the header cells, row the rows (and cards), cell the body cells.
tableElement bindable HTMLTableElementThe <table> element, empty while the cards are shown.
virtualize boolean | number200Above this number of rows only the rows in view, plus a margin, are in the page, so thousands of rows stay fast; the others are drawn while scrolling (the page, the app container or the table with --table-max-height). true always, false never. While it is on, the find of the browser and printing see only the drawn rows, and the columns keep the widths they had on the first rows.
disabled booleanfalseRead-only table, for example while the app saves: rows are not clickable and sorting, selection and resizing are off. Expanding rows still works.
selectAll booleantrueWith selectable="multiple", shows the checkbox that selects every row (in the header, or above the cards). false keeps only the checkbox of each row.

It also accepts the native attributes and events of <div> (for example id, title, aria-label, onkeydown), which are forwarded to the element.

Snippets

NameParametersDescription
cellSnippet{ row: Row; value: any; column: TableColumn<Row> }Content of the cells of custom columns, for the columns without a cell snippet.
expandedSnippet{ row: Row }Content of the detail row under an expanded row.
actionsSnippet{ row: Row }Buttons of a row, in a column that stays on the right while the table scrolls sideways.
noDataSnippetReplaces NoData when there are no rows.

Events

NameTypeDescription
onsortchange(event: { sort: TableSort | undefined }) => voidCalled when the user changes the sorting, after sort has changed.
onselectionchange(event: { selected: Row[]; selectedAll: boolean; excluded: Row[] }) => voidCalled when the user changes the selection, after selected, selectedAll and excluded have changed.
onexpandedchange(event: { expanded: (string | number)[] }) => voidCalled when the user expands or collapses a row, after expanded has changed.
onrowclick(row: Row, event: MouseEvent | KeyboardEvent) => voidCalled on a click on a row (not on its buttons, links and fields) and on Enter or Space when the row has the focus. With it every row is focusable. Calling event.preventDefault() stops the navigation of rowHref.
oncolumnstatechange(event: { columnState: TableColumnState[] }) => voidCalled when the user changes the columns (for example by resizing one), after columnState has changed.
onendreached() => voidCalled when the last rows come into view (the third from the end), again when the rows change while they are still in view and when this callback changes: for loading the next rows.

Types

Exported by the package: import type { TableColumn, TableSort, TableColumnState } from '@likable-hair/svelte';

TableColumn

A column of a Table: what it shows, how it formats, sorts and sizes it.

interface TableColumn<Row = any>

NameTypeDescription
key requiredstringUnique key of the column. Without value it is also the property of the row that the column shows.
label stringText of the header.
type 'text' | 'number' | 'date' | 'datetime' | 'boolean' | 'custom'How the value is formatted and sorted: text as is, number with Intl.NumberFormat (right-aligned, monospaced digits), date and datetime with Intl.DateTimeFormat (a Date, an ISO string, a timestamp or an object with toJSDate() such as a luxon DateTime), boolean as a check mark when true, custom with the cellSnippet of the table (sorted as text). Defaults to text.
value (row: Row) => unknownReads the value of the column from a row, for nested or computed values. Defaults to row[key].
format (value: any, row: Row) => stringTurns the value into the text of the cell, instead of the formatting of type. Not called for empty values.
numberFormat Intl.NumberFormatOptionsOptions of Intl.NumberFormat for number columns, for example { style: 'currency', currency: 'EUR' }.
dateFormat Intl.DateTimeFormatOptionsOptions of Intl.DateTimeFormat for date and datetime columns. Defaults to the day, the month and the year in digits, plus hours and minutes for datetime.
empty stringText of an empty cell (null, undefined, an empty string). Defaults to the empty of the table.
align 'start' | 'center' | 'end'Horizontal alignment of the header and the cells. Defaults to end for numbers, else start.
width stringPreferred width of the column, any CSS length (120px, 20%): columns still shrink to fit the table, minWidth keeps them wider and makes the table scroll. A width set by resizing wins.
minWidth stringMinimum width of the column, any CSS length.
maxWidth stringMaximum width of the column, any CSS length: longer text is cut with an ellipsis.
sortable booleanThe header becomes a button that sorts by this column: ascending, descending, then unsorted.
compare (a: Row, b: Row) => numberCompares two rows when the table sorts by this column on its own, instead of comparing the values. Return a negative number when a comes first in ascending order.
sort (params: { builder: FilterBuilder; direction: 'asc' | 'desc' }) => FilterBuilderAdds the sorting by this column to the query sent to the backend, instead of orderBy(key, direction). Used when the table does not sort on its own (sorting="manual", DataTable).
pinned booleanKeeps the column visible on the left while the table scrolls sideways. Pinned columns are moved before the others; they scroll like the others while, together with the checkboxes and the actions, they would take more than half of the table.
hidden booleanHides the column until it is shown through columnState (for example with a ColumnManager).
required booleanThe column is always shown: columnState cannot hide it and the ColumnManager has no button to hide it.
icon stringSVG path of the icon of the column in the ColumnManager. Defaults to an icon of its type.
description stringDescription of the column in the ColumnManager, also matched by its search. Defaults to info.
resizable booleanWith resizable on the table, false keeps this column at its size.
info stringExplanation of the column, shown in a tooltip next to the header.
footer string | Snippet<[{ rows: Row[]; column: TableColumn<Row> }]>Content of the column in the footer of the table: a text, or a snippet that receives every row, for example to show a total.
cell Snippet<[{ row: Row; value: any; column: TableColumn<Row> }]>Content of the cells of this column, instead of the formatted value.
header Snippet<[{ column: TableColumn<Row> }]>Content of the header of this column, instead of label. The sort arrow and the info icon stay.

TableSort

The sorting of a table: the key of the column and the direction.

interface TableSort

NameTypeDescription
key requiredstringKey of the sorted column.
direction required'asc' | 'desc'asc from the smallest value, desc from the largest.

TableColumnState

What the user changed about a column, in display order: plain data, ready to be saved.

interface TableColumnState

NameTypeDescription
key requiredstringKey of the column.
visible requiredbooleanWhether the column is shown.
width numberWidth in pixels set by resizing.
pinned booleanWhether the column is pinned on the left.

CSS variables

For a single instance, pass them as style props: <Table --table-background="tomato">. The --table-default-* defaults apply to the whole app: override them in :root or in a theme.

Per-instance variableDefault
--table-focus-ring-width
--table-default-focus-ring-width var(--global-focus-ring-width)
--table-focus-ring-color
--table-default-focus-ring-color var(--global-focus-ring-color)
--table-background
--table-default-background var(--global-color-surface-solid)
--table-separator-color
--table-default-separator-color var(--global-color-border)
--table-duration
--table-default-duration var(--global-duration-fast)
--table-easing
--table-default-easing var(--global-ease)
--table-width
--table-default-width 100%
--table-color
--table-default-color var(--global-color-text)
--table-font-size
--table-default-font-size 13.5px
--table-border
--table-default-border var(--global-border-width) solid var(--global-color-border)
--table-border-radius
--table-default-border-radius var(--global-radius-lg)
--table-max-height
--table-default-max-height none
--table-header-background
--table-default-header-background var(--global-color-surface-2)
--table-header-padding
--table-default-header-padding 8px 12px
--table-header-color
--table-default-header-color var(--global-color-text-3)
--table-header-font-size
--table-default-header-font-size 11px
--table-header-font-weight
--table-default-header-font-weight 500
--table-header-letter-spacing
--table-default-header-letter-spacing 0.06em
--table-header-text-transform
--table-default-header-text-transform uppercase
--table-header-sorted-color
--table-default-header-sorted-color var(--global-color-primary)
--table-sort-icon-size
--table-default-sort-icon-size 14px
--table-header-hover-color
--table-default-header-hover-color var(--global-color-text)
--table-info-icon-size
--table-default-info-icon-size 14px
--table-resizer-width
--table-default-resizer-width 2px
--table-resizer-color
--table-default-resizer-color var(--global-color-primary)
--table-cell-padding
--table-default-cell-padding 9px 12px
--table-row-background
--table-default-row-background transparent
--table-row-hover-background
--table-default-row-hover-background var(--global-color-surface-2)
--table-row-selected-hover-background
--table-default-row-selected-hover-background color-mix(in oklab, var(--global-color-primary-soft), var(--global-color-primary) 6%)
--table-row-selected-background
--table-default-row-selected-background var(--global-color-primary-soft)
--table-loading-opacity
--table-default-loading-opacity 0.55
--table-number-font-family
--table-default-number-font-family var(--global-font-family-mono)
--table-number-font-size
--table-default-number-font-size 13px
--table-date-color
--table-default-date-color var(--global-color-text-2)
--table-date-font-family
--table-default-date-font-family var(--global-font-family-mono)
--table-date-font-size
--table-default-date-font-size 13px
--table-empty-color
--table-default-empty-color var(--global-color-text-3)
--table-boolean-icon-size
--table-default-boolean-icon-size 18px
--table-boolean-color
--table-default-boolean-color var(--global-color-success)
--table-pinned-background
--table-default-pinned-background var(--global-color-surface-solid)
--table-pinned-shadow
--table-default-pinned-shadow 1px 0 0 var(--global-color-border)
--table-control-size
--table-default-control-size 40px
--table-actions-shadow
--table-default-actions-shadow -1px 0 0 var(--global-color-border)
--table-actions-gap
--table-default-actions-gap 4px
--table-expand-icon-size
--table-default-expand-icon-size 20px
--table-detail-background
--table-default-detail-background var(--global-color-bg-2)
--table-detail-padding
--table-default-detail-padding 16px 16px 16px 52px
--table-detail-color
--table-default-detail-color var(--global-color-text-2)
--table-progress-height
--table-default-progress-height 2px
--table-progress-color
--table-default-progress-color var(--global-color-primary)
--table-card-gap
--table-default-card-gap 8px
--table-card-background
--table-default-card-background var(--global-color-surface-solid)
--table-card-padding
--table-default-card-padding 12px 14px
--table-card-border
--table-default-card-border var(--global-border-width) solid var(--global-color-border)
--table-card-border-radius
--table-default-card-border-radius var(--global-radius-md)
--table-card-title-font-weight
--table-default-card-title-font-weight 600
--table-card-label-color
--table-default-card-label-color var(--global-color-text-3)
--table-card-label-font-size
--table-default-card-label-font-size 12px