Table

Rows and columns from two lists.

Display Added in v0.41.0 Updated

Default

The minimal set.
Component Variants Sizes
button secondary, outline, ghost, destructive, link sm, lg, icon
badge secondary, outline, destructive
alert destructive

{ui table,
	columns: ['Component', 'Variants', 'Sizes'],
	rows: [
		['button', 'secondary, outline, ghost, destructive, link', 'sm, lg, icon'],
		['badge', 'secondary, outline, destructive', ''],
		['alert', 'destructive', ''],
	],
	caption: 'The minimal set.',
/}

columns is the header and rows a list of rows, each a list of cells in the same order. Cells are escaped text. A cell that needs markup, such as a badge or a button, is written in {block row}.

The table scrolls sideways inside its wrapper when it is wider than the space, so it never stretches the page.

Without a caption

Name Role
Ada admin
Grace editor

{ui table,
	columns: ['Name', 'Role'],
	rows: [
		['Ada', 'admin'],
		['Grace', 'editor'],
	],
/}

Empty

Name Role
No members yet.

{ui table,
	columns: ['Name', 'Role'],
	rows: [],
	empty: 'No members yet.',
/}

When rows is empty, empty is shown in one muted row across every column, so a filtered list that matches nothing still says so. It is a string, or {block empty} when it needs markup, such as a link to add the first row. With no empty, an empty table shows just its header.

Cells with markup

Name Status
Tabs Published Open
Pagination Published Open
Modal Published Open
Toast Published Open
Carousel Published Open
Hero Published Open
Navbar Published Open
Calendar Published Open
Search Published Open
Facets Published Open
Wizard Published Open

{ui table,
	columns: ['Name', 'Status', ''],
	rows: p('docs/ui/components')->children(),
}
	{block row}
		<td>
			<a href="{$row->url()}">{$row->title}</a>
		</td>
		<td>{ui badge, title: 'Published', class: 'badge-outline' /}</td>
		<td>
			{ui button,
				title: 'Open',
				href: $row->url(),
				class: 'button-ghost',
			/}
		</td>
	{/block}
{/ui}

The block holds the row's td elements, one for each column. It runs once for each item in rows, which can be a page, an object or an array, so it is also the way to build a row from pages without mapping them first. The sort headers, the empty row and the caption work the same.

A column given as ['title' => 'Name', 'sort' => 'name'] has a header that links to its sort, in the find() syntax: name ascending, -name descending. sort is the current one, so that header carries aria-sort and links to the opposite direction. href is the link pattern, ?sort={sort} by default. With block set to the page's {fragment} that swaps the table, a header also loads it with HTMX, and the table dims while it loads. Without JavaScript the headers are plain links.

The sort comes from the URL, so accept only a column's key, with or without the leading -, before it reaches a query: a value like name,limit=9999 would add a condition to it.

{block row} replaces the cells of every row, with $row in scope, so rows can be pages or any other items with no mapping in the controller.