Table
A full-featured data table with sorting, filtering, pagination, row selection, expandable rows, column pinning, resizing, and custom cell rendering. All state is bindable.
scrollArea prop forwards behavior into it and the scroll ui slot styles it. The root is now overflow-hidden, so a bare max-h-* is enough
and anything reading the scroll offset, the action prop included, wants the viewport underneath the
root.Playground
Experiment with different props.
| Name | Role | Status | |
|---|---|---|---|
| Alice Johnson | alice@example.com | Admin | Active |
| Bob Smith | bob@example.com | Editor | Active |
| Carol Lee | carol@example.com | Viewer | Inactive |
| Dave Kim | dave@example.com | Editor | Active |
Basic Usage
Pass data - columns auto-generate from object keys.
| Name | Role | Status | |
|---|---|---|---|
| Alice Johnson | alice@example.com | Admin | Active |
| Bob Smith | bob@example.com | Editor | Active |
| Carol Lee | carol@example.com | Viewer | Inactive |
| Dave Kim | dave@example.com | Editor | Active |
<script lang="ts">
import { Table } from 'sv5ui';
const data = [
{ name: 'Alice', email: 'alice@example.com', role: 'Admin', status: 'Active' },
{ name: 'Bob', email: 'bob@example.com', role: 'Editor', status: 'Active' },
{ name: 'Carol', email: 'carol@example.com', role: 'Viewer', status: 'Inactive' }
];
</script>
<Table {data} />Custom Columns
Define columns with custom labels and alignment.
| Name | Email Address | Role | Status |
|---|---|---|---|
| Alice Johnson | alice@example.com | Admin | Active |
| Bob Smith | bob@example.com | Editor | Active |
| Carol Lee | carol@example.com | Viewer | Inactive |
| Dave Kim | dave@example.com | Editor | Active |
<Table {data} columns={[
{ key: 'name', label: 'Name' },
{ key: 'email', label: 'Email Address' },
{ key: 'role', label: 'Role', align: 'center' },
{ key: 'status', label: 'Status', align: 'right' }
]} />Sorting
Enable with sortable: true on columns. Click headers to sort.
| Alice Johnson | alice@example.com | Admin | 32 |
| Bob Smith | bob@example.com | Editor | 28 |
| Carol Lee | carol@example.com | Viewer | 35 |
| Dave Kim | dave@example.com | Editor | 41 |
| Eve Chen | eve@example.com | Admin | 29 |
| Frank Wu | frank@example.com | Viewer | 38 |
| Grace Liu | grace@example.com | Editor | 26 |
| Henry Park | henry@example.com | Viewer | 33 |
<script lang="ts">
import { Table } from 'sv5ui';
import type { SortState } from 'sv5ui';
let sorting = $state<SortState>([]);
const columns = [
{ key: 'name', label: 'Name', sortable: true },
{ key: 'email', label: 'Email', sortable: true },
{ key: 'role', label: 'Role', sortable: true },
{ key: 'age', label: 'Age', sortable: true, align: 'right' }
];
</script>
<Table {data} {columns} bind:sorting />Global Filter
Search across all columns with useDebounce to avoid filtering on every keystroke.
| Name | Role | Status | |
|---|---|---|---|
| Alice Johnson | alice@example.com | Admin | Active |
| Bob Smith | bob@example.com | Editor | Active |
| Carol Lee | carol@example.com | Viewer | Inactive |
| Dave Kim | dave@example.com | Editor | Active |
<script lang="ts">
import { Table, Input, FormField, Badge } from 'sv5ui';
import { useDebounce } from 'sv5ui';
let globalFilter = $state('');
let filterInput = $state('');
const debounce = useDebounce({ delay: 300 });
</script>
<div class="mb-3 flex items-center gap-3">
<FormField label="Search" size="sm" class="max-w-xs">
<Input
bind:value={filterInput}
placeholder="Search all columns..."
icon="lucide:search" size="sm"
oninput={() => debounce.run(() => globalFilter = filterInput)}
/>
</FormField>
{#if debounce.pending}
<Badge label="Filtering..." variant="soft" color="warning" size="xs" />
{/if}
</div>
<Table {data} bind:globalFilter />Column Filters
Provide bind:columnFilters with debounced filter inputs.
| Name | Role | Status | |
|---|---|---|---|
| Alice Johnson | alice@example.com | Admin | Active |
| Bob Smith | bob@example.com | Editor | Active |
| Carol Lee | carol@example.com | Viewer | Inactive |
| Dave Kim | dave@example.com | Editor | Active |
<script lang="ts">
import { Table, Input, FormField, Badge } from 'sv5ui';
import { useDebounce } from 'sv5ui';
let columnFilters = $state({});
let nameInput = $state('');
let roleInput = $state('');
const debounce = useDebounce({ delay: 300 });
</script>
<div class="mb-3 flex flex-wrap items-end gap-3">
<FormField label="Name" size="sm">
<Input bind:value={nameInput} placeholder="Filter name..." size="sm" class="w-36"
oninput={() => debounce.run(() => columnFilters = { ...columnFilters, name: nameInput })} />
</FormField>
<FormField label="Role" size="sm">
<Input bind:value={roleInput} placeholder="Filter role..." size="sm" class="w-36"
oninput={() => debounce.run(() => columnFilters = { ...columnFilters, role: roleInput })} />
</FormField>
{#if debounce.pending}
<Badge label="Filtering..." variant="soft" color="warning" size="xs" />
{/if}
</div>
<Table {data} bind:columnFilters />Pagination
Client-side pagination with bind:page and pageSize.
| Name | Role | Status | |
|---|---|---|---|
| Alice Johnson | alice@example.com | Admin | Active |
| Bob Smith | bob@example.com | Editor | Active |
| Carol Lee | carol@example.com | Viewer | Inactive |
<script lang="ts">
import { Table, Pagination } from 'sv5ui';
let tablePage = $state(0);
let paginationPage = $state(1);
const pageSize = 3;
</script>
<Table {data} bind:page={tablePage} {pageSize} />
<div class="mt-3 flex justify-end">
<Pagination
total={data.length}
itemsPerPage={pageSize}
bind:page={paginationPage}
onPageChange={(p) => tablePage = p - 1}
/>
</div>Infinite Scroll
useInfiniteScroll measures the element it is attached to, and the action prop hands it the root, which is overflow-hidden and never scrolls. Wrap the action so it resolves the scroll area viewport underneath first. manualPagination bypasses client-side paging.
| Name | Role | Status | |
|---|---|---|---|
| Bob 1 | user1@example.com | Editor | Inactive |
| Carol 2 | user2@example.com | Viewer | Active |
| Dave 3 | user3@example.com | Admin | Inactive |
| Eve 4 | user4@example.com | Editor | Active |
| Frank 5 | user5@example.com | Viewer | Inactive |
| Grace 6 | user6@example.com | Admin | Active |
| Henry 7 | user7@example.com | Editor | Inactive |
| Ivy 8 | user8@example.com | Viewer | Active |
| Jack 9 | user9@example.com | Admin | Inactive |
| Kate 10 | user10@example.com | Editor | Active |
Loaded: 10 rows
<script lang="ts">
import { Table, Badge } from 'sv5ui';
import { useInfiniteScroll } from 'sv5ui';
let data = $state(generateRows(1, 10));
async function loadMore() {
await new Promise((r) => setTimeout(r, 600));
data = [...data, ...generateRows(data.length + 1, 10)];
}
const { action: infiniteAction, loading } = useInfiniteScroll({ onLoad: loadMore });
// As of v2.6.0 the table scrolls inside a ScrollArea, so the root that
// the action prop receives is overflow-hidden and never fires a scroll
// event. Resolve the viewport underneath it and attach there.
const scrollAction = (node: HTMLElement) => {
const viewport = node.querySelector<HTMLElement>('[data-scroll-area-viewport]');
infiniteAction(viewport ?? node);
};
</script>
<!-- max-h bounds the root; the ScrollArea inside it does the scrolling -->
<Table
{data}
action={scrollAction}
manualPagination
sticky="header"
{loading}
class="max-h-72"
/>
<p>Loaded: {data.length} rows
{#if loading}<Badge label="Loading..." variant="soft" color="primary" size="xs" />{/if}
</p>Row Selection
Single or multiple selection with bind:selectedRows.
Single Selection
| Id | Name | Role | |
|---|---|---|---|
| 1 | Alice Johnson | alice@example.com | Admin |
| 2 | Bob Smith | bob@example.com | Editor |
| 3 | Carol Lee | carol@example.com | Viewer |
| 4 | Dave Kim | dave@example.com | Editor |
| 5 | Eve Chen | eve@example.com | Admin |
Selected: none
Multiple Selection
| Id | Name | Role | ||
|---|---|---|---|---|
| 1 | Alice Johnson | alice@example.com | Admin | |
| 2 | Bob Smith | bob@example.com | Editor | |
| 3 | Carol Lee | carol@example.com | Viewer | |
| 4 | Dave Kim | dave@example.com | Editor | |
| 5 | Eve Chen | eve@example.com | Admin |
Selected: 0 row(s)
<script lang="ts">
import { Table } from 'sv5ui';
let selectedSingle = $state([]);
let selectedMultiple = $state([]);
const data = [
{ id: 1, name: 'Alice', email: 'alice@example.com', role: 'Admin' },
{ id: 2, name: 'Bob', email: 'bob@example.com', role: 'Editor' },
{ id: 3, name: 'Carol', email: 'carol@example.com', role: 'Viewer' }
];
</script>
<!-- Single selection -->
<Table {data} selection="single" rowKey="id" bind:selectedRows={selectedSingle} />
<p>Selected: {selectedSingle[0]?.name ?? 'none'}</p>
<!-- Multiple selection with checkboxes -->
<Table {data} selection="multiple" rowKey="id" bind:selectedRows={selectedMultiple} />
<p>Selected: {selectedMultiple.length} row(s)</p>Striped
| Name | Role | Status | |
|---|---|---|---|
| Alice Johnson | alice@example.com | Admin | Active |
| Bob Smith | bob@example.com | Editor | Active |
| Carol Lee | carol@example.com | Viewer | Inactive |
| Dave Kim | dave@example.com | Editor | Active |
<Table {data} striped />Loading
| Name | Role | Status | |
|---|---|---|---|
| Alice Johnson | alice@example.com | Admin | Active |
| Bob Smith | bob@example.com | Editor | Active |
| Carol Lee | carol@example.com | Viewer | Inactive |
| Dave Kim | dave@example.com | Editor | Active |
| Name | Role | Status | |
|---|---|---|---|
| Alice Johnson | alice@example.com | Admin | Active |
| Bob Smith | bob@example.com | Editor | Active |
| Carol Lee | carol@example.com | Viewer | Inactive |
| Dave Kim | dave@example.com | Editor | Active |
<Table {data} loading />
<Table {data} loading loadingColor="success" loadingAnimation="swing" />Sticky Header
Keep the header visible while scrolling. It sticks to the top of the scroll area viewport, so bounding the table's height is all it needs.
| Name | Role | Status | |
|---|---|---|---|
| Alice Johnson | alice@example.com | Admin | Active |
| Bob Smith | bob@example.com | Editor | Active |
| Carol Lee | carol@example.com | Viewer | Inactive |
| Dave Kim | dave@example.com | Editor | Active |
| Eve Chen | eve@example.com | Admin | Active |
| Frank Wu | frank@example.com | Viewer | Inactive |
| Grace Liu | grace@example.com | Editor | Active |
| Henry Park | henry@example.com | Viewer | Active |
<!-- Bound the table's height and the header sticks to the top of
the scroll area viewport as the body scrolls under it. -->
<Table {data} sticky="header" class="max-h-64" />
<!-- sticky also takes 'footer', or true for both -->
<Table {data} sticky class="max-h-64" />Scrolling
The table sits inside a ScrollArea on both axes. scrollArea forwards behavior into it, while styling stays on the table's own scroll slot.
| Name | Role | Status | |
|---|---|---|---|
| Alice Johnson | alice@example.com | Admin | Active |
| Bob Smith | bob@example.com | Editor | Active |
| Carol Lee | carol@example.com | Viewer | Inactive |
| Dave Kim | dave@example.com | Editor | Active |
| Eve Chen | eve@example.com | Admin | Active |
| Frank Wu | frank@example.com | Viewer | Inactive |
| Grace Liu | grace@example.com | Editor | Active |
| Henry Park | henry@example.com | Viewer | Active |
<!-- The table scrolls on both axes inside a ScrollArea. Give the
root a bounded height and the vertical axis comes alive; a table
wider than its container scrolls horizontally on its own. -->
<Table {data} {columns} class="max-h-80" />
<!-- scrollArea forwards behavior into that wrapper -->
<Table {data} {columns} scrollArea={{ type: 'always', size: 'md' }} />
<Table {data} {columns} scrollArea={{ color: 'primary', track: true }} />
<!-- Styling stays on the table's own ui slots -->
<Table {data} {columns} ui={{ scroll: 'max-h-96' }} />
<!-- The root is overflow-hidden, so anything that needs to read or
drive the scroll offset wants the viewport underneath it -->
<script lang="ts">
let root = $state<HTMLElement | null>(null);
function toTop() {
root
?.querySelector('[data-scroll-area-viewport]')
?.scrollTo({ top: 0, behavior: 'smooth' });
}
</script>
<Table bind:ref={root} {data} {columns} class="max-h-80" />Empty State
| Name | |
|---|---|
| No users found. | |
<Table data={[]} columns={[
{ key: 'name', label: 'Name' },
{ key: 'email', label: 'Email' }
]} empty="No users found." />Custom Cell Rendering
Use the global cellSlot snippet or per-column cell for rich
content.
| User | Status | Role |
|---|---|---|
AJ Alice Johnson alice@example.com | Active | Admin |
BS Bob Smith bob@example.com | Active | Editor |
CL Carol Lee carol@example.com | Inactive | Viewer |
DK Dave Kim dave@example.com | Active | Editor |
EC Eve Chen eve@example.com | Active | Admin |
<script lang="ts">
import { Table, Badge, Avatar } from 'sv5ui';
</script>
<Table {data} columns={[
{ key: 'name', label: 'User' },
{ key: 'status', label: 'Status' },
{ key: 'role', label: 'Role' }
]}>
{#snippet cellSlot({ row, column, value })}
{#if column.key === 'name'}
<div class="flex items-center gap-3">
<Avatar src={row.avatar} alt={row.name} size="sm" />
<div>
<p class="font-medium">{row.name}</p>
<p class="text-on-surface/50 text-xs">{row.email}</p>
</div>
</div>
{:else if column.key === 'status'}
<Badge label={String(value)} color={value === 'Active' ? 'success' : 'surface'} variant="soft" size="xs" />
{:else}
{value}
{/if}
{/snippet}
</Table>Expandable Rows
Manage expandedRows yourself - toggle row keys via a button in cellSlot.
| Name | Role | Status | |
|---|---|---|---|
| Alice Johnson | Admin | Active | |
| Bob Smith | Editor | Active | |
| Carol Lee | Viewer | Inactive | |
| Dave Kim | Editor | Active |
<script lang="ts">
import { Table, Button } from 'sv5ui';
let expandedRows = $state([]);
</script>
<Table
{data}
columns={[
{ key: 'id', label: '' },
{ key: 'name', label: 'Name' },
{ key: 'role', label: 'Role' },
{ key: 'status', label: 'Status' }
]}
bind:expandedRows
rowKey="id"
>
{#snippet cellSlot({ column, value })}
{#if column.key === 'id'}
<Button
icon={expandedRows.includes(Number(value)) ? 'lucide:chevron-up' : 'lucide:chevron-down'}
aria-label="Details for row {value}"
aria-expanded={expandedRows.includes(Number(value))}
variant="ghost" size="xs"
onclick={() => {
const id = Number(value);
if (expandedRows.includes(id)) {
expandedRows = expandedRows.filter((k) => k !== id);
} else {
expandedRows = [...expandedRows, id];
}
}}
/>
{:else}
{value}
{/if}
{/snippet}
{#snippet expandedSlot({ row })}
<div class="space-y-1 text-sm">
<p><strong>Email:</strong> {row.email}</p>
<p><strong>Department:</strong> {row.department}</p>
<p><strong>Joined:</strong> {row.joined}</p>
</div>
{/snippet}
</Table>Nested Table
Render a child Table inside expandedSlot for master-detail views.
| Department | Lead | Members | |
|---|---|---|---|
| Engineering | Alice Johnson | 3 | |
| Design | Carol Lee | 2 | |
| Marketing | Bob Smith | 1 |
<script lang="ts">
import { Table, Button } from 'sv5ui';
let expandedRows = $state([]);
const departments = [
{ id: 'eng', name: 'Engineering', lead: 'Alice', headcount: 3,
members: [
{ name: 'Dave', role: 'Senior Engineer', email: 'dave@example.com' },
{ name: 'Henry', role: 'Engineer', email: 'henry@example.com' }
]},
{ id: 'design', name: 'Design', lead: 'Carol', headcount: 2,
members: [
{ name: 'Eve', role: 'Lead Designer', email: 'eve@example.com' },
{ name: 'Frank', role: 'UI Designer', email: 'frank@example.com' }
]}
];
</script>
<Table
data={departments}
columns={[
{ key: 'id', label: '' },
{ key: 'name', label: 'Department' },
{ key: 'lead', label: 'Lead' },
{ key: 'headcount', label: 'Members', align: 'right' }
]}
bind:expandedRows
rowKey="id"
>
{#snippet cellSlot({ column, value })}
{#if column.key === 'id'}
<Button
icon={expandedRows.includes(String(value)) ? 'lucide:chevron-up' : 'lucide:chevron-down'}
aria-label="Orders for row {value}"
aria-expanded={expandedRows.includes(String(value))}
variant="ghost" size="xs"
onclick={() => {
const id = String(value);
if (expandedRows.includes(id)) {
expandedRows = expandedRows.filter((k) => k !== id);
} else {
expandedRows = [...expandedRows, id];
}
}}
/>
{:else}
{value}
{/if}
{/snippet}
{#snippet expandedSlot({ row })}
<!-- Nested child table -->
<Table
data={row.members}
columns={[
{ key: 'name', label: 'Name' },
{ key: 'role', label: 'Role' },
{ key: 'email', label: 'Email' }
]}
ui={{ root: 'border-0 rounded-none shadow-none', thead: 'bg-surface-container/30' }}
/>
{/snippet}
</Table>Column Visibility
Toggle columns on/off via a dropdown.
| Name | Role | Status | |
|---|---|---|---|
| Alice Johnson | alice@example.com | Admin | Active |
| Bob Smith | bob@example.com | Editor | Active |
| Carol Lee | carol@example.com | Viewer | Inactive |
| Dave Kim | dave@example.com | Editor | Active |
<script lang="ts">
import { Table, Button, DropdownMenu } from 'sv5ui';
let columnVisibility = $state({ email: true, role: true, status: true });
</script>
<div class="mb-3">
<DropdownMenu items={[
{ type: 'label', label: 'Toggle Columns' },
{ type: 'separator' },
{ type: 'checkbox', label: 'Email', checked: columnVisibility.email, closeOnSelect: false,
onCheckedChange: (v) => columnVisibility = { ...columnVisibility, email: v } },
{ type: 'checkbox', label: 'Role', checked: columnVisibility.role, closeOnSelect: false,
onCheckedChange: (v) => columnVisibility = { ...columnVisibility, role: v } },
{ type: 'checkbox', label: 'Status', checked: columnVisibility.status, closeOnSelect: false,
onCheckedChange: (v) => columnVisibility = { ...columnVisibility, status: v } }
]}>
{#snippet children({ props })}
<Button variant="outline" size="sm" leadingIcon="lucide:columns-3"
label="Columns" trailingIcon="lucide:chevron-down" {...props} />
{/snippet}
</DropdownMenu>
</div>
<Table {data} bind:columnVisibility />Column Pinning
Pin columns to left or right edge.
| Name | Role | Department | Status | |
|---|---|---|---|---|
| Alice Johnson | alice@example.com | Admin | Engineering | Active |
| Bob Smith | bob@example.com | Editor | Marketing | Active |
| Carol Lee | carol@example.com | Viewer | Design | Inactive |
<Table
{data}
columns={[
{ key: 'name', label: 'Name', width: 150 },
{ key: 'email', label: 'Email', width: 200 },
{ key: 'role', label: 'Role', width: 120 },
{ key: 'department', label: 'Department', width: 150 },
{ key: 'status', label: 'Status', width: 120 }
]}
columnPinning={{ left: ['name'], right: ['status'] }}
/>Row Pinning
Pin rows to the top with bind:pinnedRows. Click the pin icon to toggle.
| Name | Role | ||
|---|---|---|---|
| Alice Johnson | alice@example.com | Admin | |
| Bob Smith | bob@example.com | Editor | |
| Carol Lee | carol@example.com | Viewer | |
| Dave Kim | dave@example.com | Editor | |
| Eve Chen | eve@example.com | Admin | |
| Frank Wu | frank@example.com | Viewer |
<script lang="ts">
import { Table, Button } from 'sv5ui';
let pinnedRows = $state([]);
</script>
<Table
{data}
columns={[
{ key: 'id', label: '' },
{ key: 'name', label: 'Name' },
{ key: 'email', label: 'Email' },
{ key: 'role', label: 'Role' }
]}
rowKey="id"
bind:pinnedRows
>
{#snippet cellSlot({ column, value })}
{#if column.key === 'id'}
<Button
icon={pinnedRows.includes(Number(value)) ? 'lucide:pin-off' : 'lucide:pin'}
aria-label="Pin row {value}"
aria-pressed={pinnedRows.includes(Number(value))}
variant="ghost" size="xs" square
color={pinnedRows.includes(Number(value)) ? 'primary' : 'surface'}
onclick={() => {
const id = Number(value);
if (pinnedRows.includes(id)) {
pinnedRows = pinnedRows.filter((k) => k !== id);
} else {
pinnedRows = [...pinnedRows, id];
}
}}
/>
{:else}
{value}
{/if}
{/snippet}
</Table>Resizable Columns
Drag a column border, or focus it and use the keyboard. Each border is a separator in the tab order that reports its width through aria-valuenow, so a column can be resized without a pointer. Dragging goes through the shared pointer
hook, which means touch and pen work as well as a mouse.
Resize keys
With a column border focused.
| Keys | Action |
|---|---|
Tab | Reach the border. Every resizable column has one, right of its header |
Left, Right | Narrow or widen by 16px |
Shift + Left, Right | By 64px |
Home | Snap to the column's minWidth, 50px unless you set one |
End | Snap to maxWidth. Does nothing when the column has no maximum |
| Name | Role | |
|---|---|---|
| Alice Johnson | alice@example.com | Admin |
| Bob Smith | bob@example.com | Editor |
| Carol Lee | carol@example.com | Viewer |
<Table {data} columns={[
{ key: 'name', label: 'Name', resizable: true, width: 200 },
{ key: 'email', label: 'Email', resizable: true, width: 250 },
{ key: 'role', label: 'Role', resizable: true, width: 120 }
]} />Row Callbacks
Click and right-click handlers.
| Name | Role | Status | |
|---|---|---|---|
| Alice Johnson | alice@example.com | Admin | Active |
| Bob Smith | bob@example.com | Editor | Active |
| Carol Lee | carol@example.com | Viewer | Inactive |
| Dave Kim | dave@example.com | Editor | Active |
<script lang="ts">
import { Table } from 'sv5ui';
import { toast } from 'sv5ui';
</script>
<Table
{data}
onRowClick={(row) => toast(`Clicked: ${row.name}`)}
onRowContextmenu={(row) => toast(`Right-clicked: ${row.name}`)}
/>UI Slots
Use the ui prop to override classes.
| Slot | Description |
|---|---|
root | Outer wrapper. Clips its content and carries the border |
scroll | ScrollArea wrapping the table on both axes |
base | Table element |
caption | Table caption (sr-only) |
thead | Table header |
tbody | Table body |
tfoot | Table footer |
tr | Table row |
th | Header cell |
td | Data cell |
separator | Pinned rows separator |
empty | Empty state cell |
loading | Loading state |
| Name | Role | Status | |
|---|---|---|---|
| Alice Johnson | alice@example.com | Admin | Active |
| Bob Smith | bob@example.com | Editor | Active |
| Carol Lee | carol@example.com | Viewer | Inactive |
<!-- Card-style with gradient header -->
<Table {data} striped ui={{
root: 'rounded-2xl shadow-xl border-0 overflow-hidden',
thead: 'bg-gradient-to-r from-primary/10 to-tertiary/10',
th: 'text-primary font-bold tracking-wider',
tbody: 'divide-y-0',
td: 'py-4'
}} />Snippets
| Snippet | Description |
|---|---|
headerSlot | Global header cell override (receives column, sortDirection, toggleSort) |
cellSlot | Global data cell override (receives row, column, value) |
expandedSlot | Expanded row content (receives row, rowIndex) |
emptySlot | Custom empty state |
loadingSlot | Custom loading state |
captionSlot | Custom caption |
bodyTopSlot | Content before data rows |
bodyBottomSlot | Content after data rows |
Custom header with sort indicator
| Role | ||
|---|---|---|
| Alice Johnson | alice@example.com | Admin |
| Bob Smith | bob@example.com | Editor |
| Carol Lee | carol@example.com | Viewer |
<!-- Custom header with Button sort indicator -->
<Table {data} columns={columns}>
{#snippet headerSlot({ column, sortDirection, toggleSort })}
{#if column.sortable}
<Button
variant="ghost" size="xs"
label={column.label}
trailingIcon={sortDirection === 'asc' ? 'lucide:arrow-up'
: sortDirection === 'desc' ? 'lucide:arrow-down'
: 'lucide:arrows-up-down'}
color={sortDirection ? 'primary' : 'surface'}
onclick={toggleSort}
ui={{ base: 'uppercase tracking-wider font-semibold' }}
/>
{:else}
<span class="font-semibold uppercase">{column.label}</span>
{/if}
{/snippet}
</Table>Custom empty state
| Name | |
|---|---|
No results found Try adjusting your search or filters. | |
<!-- Custom empty state with Empty component -->
<Table data={[]} {columns}>
{#snippet emptySlot()}
<Empty
icon="lucide:search-x"
title="No results found"
description="Try adjusting your search or filters."
variant="soft"
size="sm"
actions={[{ label: 'Clear Filters', variant: 'outline', color: 'surface', size: 'xs' }]}
/>
{/snippet}
</Table>Props
| Prop | Type | Default |
|---|---|---|
data | T[] | [] |
columns | TableColumn<T>[] | auto |
rowKey | keyof T | - |
caption | string | - |
sorting | SortState | [] |
multiSort | boolean | false |
globalFilter | string | - |
columnFilters | Record<string, string> | - |
page | number | 0 |
pageSize | number | 10 |
selection | 'single' | 'multiple' | - |
selectedRows | T[] | [] |
expandedRows | (string|number)[] | [] |
columnVisibility | Record<string, boolean> | - |
columnPinning | { left?, right? } | - |
pinnedRows | (string|number)[] | - |
columnSizing | Record<string, number> | - |
loading | boolean | false |
loadingColor | ColorType | 'primary' |
striped | boolean | false |
hoverable | boolean | true |
sticky | boolean | 'header' | 'footer' | false |
action | Action<HTMLElement> | - |
scrollArea | ScrollAreaOptions | - |
empty | string | 'No data.' |
onRowClick | (row, index, event) => void | - |
class | string | - |
ui | Record<Slot, Class> | - |
Column Props
Each column in the columns array accepts these properties.
| Prop | Type | Default |
|---|---|---|
key | keyof T | - |
label | string | auto |
sortable | boolean | false |
sortFn | (a, b) => number | - |
filterable | boolean | false |
filterFn | (row, value) => boolean | - |
pinned | 'left' | 'right' | - |
resizable | boolean | false |
width | number | - |
minWidth | number | 50 |
maxWidth | number | - |
align | 'left' | 'center' | 'right' | 'left' |
visible | boolean | true |
header | Snippet | - |
cell | Snippet | - |
footer | Snippet | - |
When You Need More
Table is markup: a real HTML table you hand rows and columns, with sorting and selection for
the cases where a page needs them. Once the data outgrows that, @sv5ui/datagrid is the separate package built for it.
Stay with Table
- A page of rows you already have in hand
- Custom markup per cell, expanded rows, your own footer
- Sorting and selection over a handful of records
Reach for DataGrid
- Thousands of rows in a scroll viewport
- Column filters, resize, reorder, pin and hide
- Inline editing with validation, undo and paste
- Filter, sort and paging driven by a server