Reference
DataTable
Rows of records with their columns declared once: a column sorts when it is .sortable (its header a button, aria-sort saying which way), cell(r) { … } draws a cell, empty { … } shows when there are no rows, and bind: chooses rows (a list with .multiple, a box for each and one for all).
DataTable(rows: [Item], key: (Item) -> String or (Item) -> Number, bind: State, …) { … }
Since 6.2.0
multiple
label
| Region | Status | |||
|---|---|---|---|---|
| checkout | fra1 | 4 | Live | |
| search | iad1 | 11 | Failed | |
| accounts | sin1 | 7 | Live |
0 chosen
Example
state deploys = [{ id: "d1", service: "checkout", region: "fra1", minutes: 4, status: "Live" }, { id: "d2", service: "search", region: "iad1", minutes: 11, status: "Failed" }, { id: "d3", service: "accounts", region: "sin1", minutes: 7, status: "Live" }]
state chosen: [String] = []
DataTable(rows: deploys, key: d => d.id, bind: chosen, label: "Deploys").multiple {
DataTable.Column("Service", value: d => d.service).sortable
DataTable.Column("Region", value: d => d.region)
DataTable.Column("Minutes", value: d => d.minutes).sortable
DataTable.Column("Status") {
cell(d) { Badge(d.status, tone: if d.status == "Live" { .success } else { .danger }) }
}
}
Text("{chosen.length} chosen").muted
What it shows with no rows
state deploys = [{ id: "d1", service: "checkout", status: "Live" }]
DataTable(rows: deploys.filter(d => d.status == "Paused"), key: d => d.id, label: "Paused deploys") {
empty { EmptyState(icon: "list", title: "Nothing is paused") }
DataTable.Column("Service", value: d => d.service)
}
One row at a time, filtered and paged
state q = ""
state picked = ""
state people = [{ id: "1", name: "Ada Lovelace", team: "Compiler" }, { id: "2", name: "Grace Hopper", team: "Runtime" }, { id: "3", name: "Alan Turing", team: "Compiler" }]
Input(bind: q, label: "Search").search
DataTable(rows: people, key: p => p.id, bind: picked, label: "People", filter: q, pageSize: 2) {
DataTable.Column("Name", value: p => p.name).sortable
DataTable.Column("Team", value: p => p.team)
}
Props
| Prop | Type | Unset | Meaning |
|---|---|---|---|
rows: | [Item] (required) | — | The records, a row each |
key: | (Item) -> String or (Item) -> Number (required) | — | What tells two rows apart: |
bind: | State | none: rows are not chosen | The state holding the chosen row's key (a radio a row), or with |
multiple: | Bool | false | Several rows at once, with a box in the header that takes them all. Written as a flag, |
label: | String (required) | — | What the table is: its caption, visually hidden, read by a screen reader |
filter: | String | none: every row | Only the rows where a column's |
pageSize: | Number |
| Rows a page, behind Previous and Next with |
Attribute families: global, aria, data. Plus the 22 universal props every element takes: animate:, exit:, speed:, duration:, delay:, easing:, stagger:, on:, count:, shared:, class:, ref:, drag:, dragGroup:, dropValue:, dropAxis:, dropInside:, roving:, trapFocus:, mount:, update:, cleanup:.
Flags and cases
A flag is written after the parentheses with a dot: a Bool prop, or a case of one of the element's enum props. A case the enum lacks is an error with a hint.
.multiple
Events
Every element also takes the props, the events and the attribute families listed on every element.
Slots
children
Parts
The parts of DataTable are written under its name, inside it. Each is described here, with what it takes.
DataTable.Column
One column: its title, its value: (what it shows and sorts by), and a cell(r) { … } that draws it instead.
DataTable.Column(_ title: String, value: (Item) -> String or (Item) -> Number or (Item) -> Bool or (Item) -> Money, sortable: Bool)
| Prop | Type | Unset | Meaning |
|---|---|---|---|
title | String (positional) | — | Its header |
value: | (Item) -> String or (Item) -> Number or (Item) -> Bool or (Item) -> Money | none | What the column holds for a row: |
sortable: | Bool | false | Its header is a button that sorts the rows by its |
.sortable
Renders with the class wf-data-table, stable across releases, so a stylesheet may target it.