Table
| Invoice | Status | Method | Amount |
|---|---|---|---|
| INV-001 | Paid | Card | $250.00 |
| INV-002 | Pending | Bank transfer | $150.00 |
| INV-003 | Paid | Card | $350.00 |
| Total | $750.00 | ||
Installation
npx @mielui/svelte add tableyarn dlx @mielui/svelte add tablebunx @mielui/svelte add tableUsage
Root renders a native table. Wrap it in ScrollArea when the columns can be wider than the page. Leave out Caption or Footer when the data does not need them, and set class on any part to change alignment, wrapping, or column widths.
<script lang="ts">
import * as Table from '@mielui/svelte/components/table';
</script>
<Table.ScrollArea tabindex={0} aria-label="Invoices">
<Table.Root>
<Table.Caption>September invoices</Table.Caption>
<Table.Header>
<Table.Row>
<Table.Head>Invoice</Table.Head>
<Table.Head>Amount</Table.Head>
</Table.Row>
</Table.Header>
<Table.Body>
<Table.Row>
<Table.Cell>INV-001</Table.Cell>
<Table.Cell>$250.00</Table.Cell>
</Table.Row>
</Table.Body>
</Table.Root>
</Table.ScrollArea>
Head defaults to scope="col". Set scope="row" for row headings. Head and Cell take the native colspan, rowspan, and headers attributes. Set data-state="selected" on a Row to give it the selected wash.
Examples
Inset
The default table has no frame: muted column headings, hairline row dividers, and a wash on the hovered row. variant="inset" puts the header and footer on an outer frame and the body rows on a recessed surface inside it.
| Invoice | Status | Method | Amount |
|---|---|---|---|
| INV-001 | Paid | Card | $250.00 |
| INV-002 | Pending | Bank transfer | $150.00 |
| INV-003 | Paid | Card | $350.00 |
| Total | $750.00 | ||
Sorting and selection
Table keeps no state. Put a Button in the heading to sort and update aria-sort when the order changes. Keep the selected rows in your own state and mark them with data-state="selected".
| Dashboard | |
| Mobile app | |
| Website |
0 selected
API reference
Table.Root
variant"default" | "inset"insetputs the header and footer on an outer frame and the body rows on a recessed surface.Default
'default'
Other parts
These parts have no props of their own. They pass HTML attributes and events to their element.
Table.BodyTable.CaptionTable.CellTable.FooterTable.HeadTable.HeaderTable.RowTable.ScrollArea
pnpm dlx @mielui/svelte add table