Table
A flexible component for displaying tabular data with customizable cell rendering using Svelte snippets.
Props
Prop | Type | Default | Description |
|---|---|---|---|
caption | string | '' | An optional caption for the table. |
tableHeadItems | Array<T> | required | Data for the header row. |
tableRowItems | Array<Array<U>> | required | Data for the body rows. |
tableFooterItems | Array<V> | required | Data for the footer row. |
headTemplate | Snippet<[T]> | required | Snippet for rendering header cells. |
bodyTemplate | Snippet<[U]> | required | Snippet for rendering body cells. |
footerTemplate | Snippet<[V]> | required | Snippet for rendering footer cells. |
class | string | '' | CSS classes for the table element. |
captionClass | string | '' | CSS classes for the caption element. |
headClass | string | '' | CSS classes for the thead element. |
bodyClass | string | '' | CSS classes for the tbody element. |
rowClass | string | '' | CSS classes for tr elements. |
cellClass | string | '' | CSS classes for th and td elements. |
footerClass | string | '' | CSS classes for the tfoot element. |
overrideDefaultStyling | boolean | false | If true, removes default fluid-table classes. |
Samples
Standard Table
A basic table with header, body, and footer.
| ID | Name | Age |
|---|---|---|
| 1 | Alice | 30 |
| 2 | Bob | 24 |
| 3 | Charlie | 35 |
| Total | 3 Users |
0
<Table 1
caption="User Directory"2
tableHeadItems={['ID', 'Name']}3
tableRowItems={[[1, 'Alice'], [2, 'Bob']]}4
tableFooterItems={['Total', '2']}5
>6
{#snippet headTemplate(item)} {item} {/snippet}7
{#snippet bodyTemplate(item)} {item} {/snippet}8
{#snippet footerTemplate(item)} <strong>{item}</strong> {/snippet}9
</Table>Styled Table
Applying custom classes to specific table sections.
| ID | Name | Age |
|---|---|---|
| 1 | Alice | 30 |
| 2 | Bob | 24 |
| 3 | Charlie | 35 |
0
<Table 1
tableHeadItems={headers} 2
tableRowItems={users}3
headClass="bg-primary-500 text-white"4
rowClass="hover:bg-neutral-100"5
>6
...7
</Table>