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

Deploys
RegionStatus
checkoutfra14Live
searchiad111Failed
accountssin17Live

0 chosen

Example

wf

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

wf

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

wf

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

Props of DataTable
PropTypeUnsetMeaning

rows:

[Item] (required)

—

The records, a row each

key:

(Item) -> String or (Item) -> Number (required)

—

What tells two rows apart: r => r.id; what bind: holds, and what keeps a row's nodes as it moves

bind:

State

none: rows are not chosen

The state holding the chosen row's key (a radio a row), or with .multiple a list of keys (a box a row and one for all); without it, no column to choose

multiple:

Bool

false

Several rows at once, with a box in the header that takes them all. Written as a flag, .multiple, or multiple: true.

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 value: holds this text, its case ignored; a column with only cell is not searched. A change goes back to page 1

pageSize:

Number

0: every row

Rows a page, behind Previous and Next with 1–20 of 54; 0 shows every row. Whether there are pages is decided when it is drawn

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)
Props of DataTable.Column
PropTypeUnsetMeaning

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: r => r.service; shown as text unless cell(r) draws it, and what sorting and filter: read

sortable:

Bool

false

Its header is a button that sorts the rows by its value:, ascending then descending (aria-sort); needs value:. Written as a flag, .sortable, or sortable: true.

.sortable

Renders with the class wf-data-table, stable across releases, so a stylesheet may target it.