Table

A simple read-only table with a caption, row headers and an empty state.

Invoices this month
InvoiceCustomerStatusAmount
INV-2041Harbor Supply Co.Paid$1,840.00
INV-2042Juniper DentalDue$620.00
INV-2043Northpeak OutfittersOverdue$3,275.50
INV-2044Lumen SchoolsPaid$990.00

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/data-table

Usage

import { DataTable } from "./ui/uicontext/components/DataTable.ts"
interface Project {	readonly id: string	readonly name: string	readonly owner: string}export const ProjectTable = <M>(h: Html.H<M>, projects: ReadonlyArray<Project>) =>	DataTable(h, {		caption: "Projects",		rows: projects,		rowKey: (project) => project.id,		empty: "No projects yet.",		columns: [			{ key: "name", heading: "Name", rowHeader: true, cell: (project) => project.name },			{ key: "owner", heading: "Owner", cell: (project) => project.owner },		],	})

Examples

Empty

With no rows, the table keeps its headings and says why it's empty.

Deploys today
ServiceTime
Nothing deployed today.

API reference

Options

DataTable options
NameTypeDescription
captionstringA title above the table that names what it lists, read first by screen readers
rowsrequiredRow[]The rows to show, in order
rowKeyrequired(row: Row) => stringA stable id for each row, so rows keep their place when the list changes
columnsrequiredreadonly [Column<Row, Message, R>, ...Column<Row, Message, R>[]]At least one column: its header, its cell, and whether it heads the row
emptyrequiredstringWhat the table says when there are no rows

Accessibility

  • A native table with a caption; column headers have scope="col" and row headers scope="row".
  • With no rows, it says so in one cell across the table.

Source