humanonlyweb/ui

Table

A data table with custom cells.

Markdown

Examples

Basic

Contributors
MemberRoleCommits
ALAda Lovelace ada@example.comMaintainer1,243
GHGrace Hopper grace@example.comReviewer812
ATAlan Turing alan@example.comContributor97
Copy code

Custom cells

Replace any cell, header or footer with the <key>-cell, <key>-header and <key>-footer slots.

InvoiceStatusAmount
INV-001 Acme Inc.paid$1,200
INV-002 Globexdue$860
INV-003 Initechoverdue$2,400
$4,460
Copy code

Sorting

Mark a column sortable and its header becomes a button that sets v-model:sort. The table doesn't reorder rows: sort them yourself, or on the server.

Packages
vite390031,000,000
zod59026,000,000
vue1127,100,000
nuxt8201,050,000
Copy code

Empty

Members
NameEmail

No members yet

Copy code

API

PropTypeDefault
columns*

Column definitions: key, header, and optional accessor, align, numeric, width.

TableColumn<T>[]โ€”
rows*

Row data.

T[]โ€”
rowKey

Stable key per row: a property name or a function. Defaults to the index.

((row: T, index: number) => PropertyKey) | keyof Tโ€”
caption

Visible caption. Also names the scroll region.

stringโ€”
sort

The sorted column and direction, set by sortable columns' headers. Rows aren't reordered for you.

TableSortโ€”
EventPayload
update:sort

v-model:sort update.

[value: TableSort | undefined]
SlotProps
empty

Shown when there are no rows.

โ€”
sort-indicator

Replaces a sortable header's direction arrow.

{ direction: "ascending" | "descending" | undefined; }

Types

export interface TableColumn<T> {
  key: string;
  header: string;
  accessor?: (row: T) => unknown;
  align?: TdHTMLAttributes["align"];
  numeric?: boolean;
  width?: `${number}px` | `${number}%`;
  /** Its header becomes a button that sets the table's `v-model:sort`. */
  sortable?: boolean;
}

/** A table's sort: which column, which way. Sorting the rows is up to you. */
export interface TableSort {
  key: string;
  direction: "ascending" | "descending";
}
Copy code

Styling

Parts
table-scrolltabletable-captiontable-headertable-rowtable-celltable-sorttable-sort-indicatortable-emptytable-footer
States
data-table-overflowdata-table-aligndata-table-numericdata-table-sort

Accessibility

  • A table wider than its container scrolls in a region named by caption, focusable so the keyboard can scroll it.