Table
A data table with custom cells.
MarkdownExamples
Basic
| Member | Role | Commits |
|---|---|---|
| AL | Maintainer | 1,243 |
| GH | Reviewer | 812 |
| ATAlan Turing alan@example.com | Contributor | 97 |
Custom cells
Replace any cell, header or footer with the <key>-cell, <key>-header and <key>-footer slots.
| Invoice | Status | Amount | |
|---|---|---|---|
| INV-001 Acme Inc. | paid | $1,200 | |
| INV-002 Globex | due | $860 | |
| INV-003 Initech | overdue | $2,400 | |
| $4,460 |
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.
| vite | 3900 | 31,000,000 |
| zod | 590 | 26,000,000 |
| vue | 112 | 7,100,000 |
| nuxt | 820 | 1,050,000 |
Empty
| Name | |
|---|---|
No members yet | |
API
| Prop | Type | Default |
|---|---|---|
columns*Column definitions: | TableColumn<T>[] | โ |
rows*Row data. | T[] | โ |
rowKeyStable key per row: a property name or a function. Defaults to the index. | ((row: T, index: number) => PropertyKey) | keyof T | โ |
captionVisible caption. Also names the scroll region. | string | โ |
sortThe sorted column and direction, set by | TableSort | โ |
| Event | Payload |
|---|---|
update:sort
| [value: TableSort | undefined] |
| Slot | Props |
|---|---|
emptyShown when there are no rows. | โ |
sort-indicatorReplaces 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 codeStyling
- 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.