Data Grid

View as Markdown

A spreadsheet-like grid for editing records, with typed columns, sorting and grouping.

IssueStatusPriorityAssigneeLabelsEstimateDueImpact
ENG-142Sign-in link expires before the email arrivesIn ProgressUrgentAda LovelaceBug3Dec 4★★★
ENG-139Keyboard shortcuts for triageTodoHighGrace HopperFeature5Dec 11★★★
ENG-137Export drops the last row of a filtered viewIn ReviewHighAlan TuringBug2Dec 3★★★
ENG-135Draft release notes for 2.4In ProgressMediumScout1Dec 6★★★
ENG-131Empty states for saved viewsTodoMediumAda LovelaceDesign3★★★
ENG-128Notifications arrive twice on mobileTodoLowBug★★★
ENG-126Bulk move issues between teamsIn ReviewMediumGrace HopperFeature8Dec 9★★★
ENG-121Webhook retries with backoffDoneHighAlan TuringFeature5Nov 27★★★
ENG-118Dark mode contrast on badgesDoneLowAda LovelaceDesign1Nov 24★★★
ENG-144Invoice PDF cuts off long company namesTodoUrgentGrace HopperBug2Dec 2★★★
ENG-140SAML sign-in for the admin consoleIn ProgressHighAlan TuringFeature8Dec 18★★★
ENG-133Triage suggestions for new bug reportsIn ReviewMediumScoutFeature3Dec 10★★★
12 rows
ReturnF2
Edit the cell, or type to replace it; Escape cancels and Tab saves and moves
Shift Down arrowShift Right arrow
Stretch a range of cells; Shift+click or drag does too
Command CCommand V
Copy or paste cells as tab-separated text; one value pasted fills the range
Command D
Fill down from the range's top row, or from the row above
Forward delete
Clear the cell or the range
Command ZCommand Shift Z
Undo or redo your last change
Option Shift Right arrow
Move a column, on its header
JDown arrow
Next record
KUp arrow
Previous record
Shift JShift K
Extend the selection
X
Select or unselect
Space
Peek at the record; Escape closes it
Return
Open the record
S
Change Status on the focused or selected records
P
Change Priority on the focused or selected records
A
Change Assignee on the focused or selected records
Escape
Clear the selection

When to use

A spreadsheet-like grid for editing records, with typed columns, sorting and grouping. Use Table instead when the table is read-only.

Usage

import type { Outcome } from "./ui/uicontext/components/domain/Outcome.ts"import { type Item, type Property, View } from "./ui/uicontext/components/domain/Record.ts"import { Table } from "./ui/uicontext/components/Table.ts"import { Value } from "./ui/uicontext/components/Property.ts"
const Message = UiSchema.TaggedEnum({	RequestedEditTask: { request: Schema.String, item: Schema.String, key: Schema.String, value: Value },	ChangedTaskView: { view: View },})interface Model {	readonly tasks: ReadonlyArray<Item>	readonly fields: ReadonlyArray<Property>	readonly view: View	readonly outcomes: ReadonlyArray<Outcome>}export const Tasks = (h: Html.H<typeof Message.Type>, { tasks, fields, view, outcomes }: Model) =>	Table(h, {		props: { label: "Tasks", records: tasks, fields, view, title: { label: "Task", editable: true }, outcomes },		onEmit: {			// save the edit, then answer with { _tag: "Accepted" | "Refused", request } in `outcomes`			RequestedEdit: (edit) => Message.RequestedEditTask(edit),			// sorting, resizing and hiding columns come back as the next view			RequestedView: ({ view }) => Message.ChangedTaskView({ view }),			RequestedOpen: () => undefined,			RequestedCreate: () => undefined,			RequestedAction: () => undefined,			RequestedReorder: () => undefined,			RequestedCellAction: () => undefined,			RequestedAddColumn: () => undefined,			RequestedColumnAction: () => undefined,			Selected: () => undefined,		},	})

Examples

Editing

Edits are requests the app accepts or refuses. This one refuses estimates over 8 and closing an unassigned issue.

IssueStatusPriorityAssigneeEstimate
1ENG-135Draft release notes for 2.4In ProgressMediumScout1
2ENG-131Empty states for saved viewsTodoMediumAda Lovelace3
3ENG-128Notifications arrive twice on mobileTodoLow
4ENG-126Bulk move issues between teamsIn ReviewMediumGrace Hopper8
5ENG-121Webhook retries with backoffDoneHighAlan Turing5
5 rows

Estimates above 8, and closing an unassigned issue, are refused in this example.

Grouping

Rows grouped by priority, sorted by due date within each group. Click a group's header to fold it.

IssueStatusAssigneeLabelsEstimateDue
Urgent 2
ENG-144Invoice PDF cuts off long company namesTodoGrace HopperBug2Dec 2
ENG-142Sign-in link expires before the email arrivesIn ProgressAda LovelaceBug3Dec 4
High 4
ENG-121Webhook retries with backoffDoneAlan TuringFeature5Nov 27
ENG-137Export drops the last row of a filtered viewIn ReviewAlan TuringBug2Dec 3
ENG-139Keyboard shortcuts for triageTodoGrace HopperFeature5Dec 11
ENG-140SAML sign-in for the admin consoleIn ProgressAlan TuringFeature8Dec 18
Medium 4
ENG-135Draft release notes for 2.4In ProgressScout1Dec 6
ENG-126Bulk move issues between teamsIn ReviewGrace HopperFeature8Dec 9
ENG-133Triage suggestions for new bug reportsIn ReviewScoutFeature3Dec 10
ENG-131Empty states for saved viewsTodoAda LovelaceDesign3
Low 2
ENG-118Dark mode contrast on badgesDoneAda LovelaceDesign1Nov 24
ENG-128Notifications arrive twice on mobileTodoBug
12 rows· This example only groups and sorts.

Frozen and moved columns

The title and Status stay in place while the rest scroll. Freeze from a column's menu, drag a header to move it, or drag its edge to resize it.

IssueStatusPriorityAssigneeLabelsEstimateDueCustomerImpact
1ENG-142Sign-in link expires before the email arrivesIn ProgressUrgentAda LovelaceBug3Dec 4Northwind Freight★★★
2ENG-139Keyboard shortcuts for triageTodoHighGrace HopperFeature5Dec 11★★★
3ENG-137Export drops the last row of a filtered viewIn ReviewHighAlan TuringBug2Dec 3Halcyon Health★★★
4ENG-135Draft release notes for 2.4In ProgressMediumScout1Dec 6★★★
5ENG-131Empty states for saved viewsTodoMediumAda LovelaceDesign3★★★
6ENG-128Notifications arrive twice on mobileTodoLowBugBluebird Credit Union★★★
7ENG-126Bulk move issues between teamsIn ReviewMediumGrace HopperFeature8Dec 9Northwind Freight★★★
8ENG-121Webhook retries with backoffDoneHighAlan TuringFeature5Nov 27Halcyon Health★★★
9ENG-118Dark mode contrast on badgesDoneLowAda LovelaceDesign1Nov 24★★★
10ENG-144Invoice PDF cuts off long company namesTodoUrgentGrace HopperBug2Dec 2Bluebird Credit Union★★★
11ENG-140SAML sign-in for the admin consoleIn ProgressHighAlan TuringFeature8Dec 18Halcyon Health★★★
12ENG-133Triage suggestions for new bug reportsIn ReviewMediumScoutFeature3Dec 10★★★
12 rows· This example only arranges columns.

A CRM base

Companies with typed columns: links, currency, ratings and people.

CompanyStageOwnerARRWin probabilityFitWebsiteBilling emailPhoneContractsPrimary contactOpen dealsARR per seat
Northwind FreightCustomerMaya Chen$184,000100%★★★★★northwind.example[email protected]+1 415 555 0142northwind-msa.pdfPriya Raman2$460
Halcyon HealthTrialOmar Haddad$065%★★★★★halcyon.example[email protected]+1 617 555 0199Jonas Berg1#ERROR
Bluebird Credit UnionCustomerLena Fischer$96,000100%★★★★★bluebird.example[email protected]+1 312 555 0110bluebird-order-form.pdfbluebird-dpa.pdfSofia Alvarez0$320
Orchard RoboticsLeadMaya Chen$020%★★★★★orchard.exampleKenji Watanabe1$0
Lumen SchoolsTrialOmar Haddad$42,00045%★★★★★lumen.example[email protected]+44 20 7946 0321Amara Okafor3$140
Kestrel LogisticsChurnedLena Fischer$00%★★★★★kestrel.example[email protected]+1 206 555 0187kestrel-msa.pdfTom Hughes0$0
6 rows

Try lowering Northwind Freight's ARR: the app refuses, the old value comes back and a toast says why.

Five thousand rows

Only the rows near the visible part are drawn, so scrolling, sorting and editing stay quick.

IssueStatusPriorityAssigneeEstimateDueImpact
ENG-5000Billing times out for large workspacesTodoUrgentAda LovelaceJan 1★★★
ENG-4748Notifications ignores the saved filterTodoUrgentAlan TuringJan 1★★★
ENG-4496Billing times out for large workspacesTodoUrgentJan 1★★★
ENG-4244Notifications ignores the saved filterTodoUrgentGrace HopperJan 1★★★
ENG-3992Billing times out for large workspacesTodoUrgentScoutJan 1★★★
ENG-3740Notifications ignores the saved filterTodoUrgentAda LovelaceJan 1★★★
ENG-3488Billing times out for large workspacesTodoUrgentAlan TuringJan 1★★★
ENG-3236Notifications ignores the saved filterTodoUrgentJan 1★★★
ENG-2984Billing times out for large workspacesTodoUrgentGrace HopperJan 1★★★
ENG-2732Notifications ignores the saved filterTodoUrgentScoutJan 1★★★
ENG-2480Billing times out for large workspacesTodoUrgentAda LovelaceJan 1★★★
ENG-2228Notifications ignores the saved filterTodoUrgentAlan TuringJan 1★★★
ENG-1976Billing times out for large workspacesTodoUrgentJan 1★★★
ENG-1724Notifications ignores the saved filterTodoUrgentGrace HopperJan 1★★★
ENG-1472Billing times out for large workspacesTodoUrgentScoutJan 1★★★
ENG-1220Notifications ignores the saved filterTodoUrgentAda LovelaceJan 1★★★
ENG-968Billing times out for large workspacesTodoUrgentAlan TuringJan 1★★★
ENG-716Notifications ignores the saved filterTodoUrgentJan 1★★★
ENG-464Billing times out for large workspacesTodoUrgentGrace HopperJan 1★★★
ENG-212Notifications ignores the saved filterTodoUrgentScoutJan 1★★★
ENG-4775Sign-in sends a duplicate emailDoneUrgentAda LovelaceJan 2★★★
ENG-4523Admin console needs an empty stateDoneUrgentAlan TuringJan 2★★★
ENG-4271Sign-in sends a duplicate emailDoneUrgentJan 2★★★
ENG-4019Admin console needs an empty stateDoneUrgentGrace HopperJan 2★★★
ENG-3767Sign-in sends a duplicate emailDoneUrgentScoutJan 2★★★
ENG-3515Admin console needs an empty stateDoneUrgentAda LovelaceJan 2★★★
ENG-3263Sign-in sends a duplicate emailDoneUrgentAlan TuringJan 2★★★
ENG-3011Admin console needs an empty stateDoneUrgentJan 2★★★
ENG-2759Sign-in sends a duplicate emailDoneUrgentGrace HopperJan 2★★★
ENG-2507Admin console needs an empty stateDoneUrgentScoutJan 2★★★
ENG-2255Sign-in sends a duplicate emailDoneUrgentAda LovelaceJan 2★★★
ENG-2003Admin console needs an empty stateDoneUrgentAlan TuringJan 2★★★
ENG-1751Sign-in sends a duplicate emailDoneUrgentJan 2★★★
ENG-1499Admin console needs an empty stateDoneUrgentGrace HopperJan 2★★★
ENG-1247Sign-in sends a duplicate emailDoneUrgentScoutJan 2★★★
ENG-995Admin console needs an empty stateDoneUrgentAda LovelaceJan 2★★★
ENG-743Sign-in sends a duplicate emailDoneUrgentAlan TuringJan 2★★★
ENG-491Admin console needs an empty stateDoneUrgentJan 2★★★
ENG-239Sign-in sends a duplicate emailDoneUrgentGrace HopperJan 2★★★
ENG-4802Mobile app loses the draft on reloadIn ReviewUrgentScoutJan 3★★★
5,000 rows

API reference

Props

Table props
NameTypeDefaultDescription
labelrequiredstring—The table's accessible name: "Tasks"
agentIdstringtable:<label>This table's id for agents, unique on the page; table:<label> by default
recordsrequiredItem[]—The records to show, in the order the app gives them
fieldsrequiredProperty[]—Every field, in its own order; the view hides and orders them
viewViewInput—How the records show: sort, groupBy, hidden, order, widths and filter
title{ label, width, editable }—The first, frozen column: the record's title. editable makes it a text cell
shortcutsFieldShortcut[]—Single keys that open a field's picker on the focused or selected rows: { key: "s", field: "stage" }
selectablebooleantrueA checkbox per row and the action bar; true by default
actionsItemAction[]—Actions offered on each record, such as archive or delete
createstring—An "add row" button with this label, emitting RequestedCreate; absent hides it (a synced table)
focusRecordstring—A record the app just added: its first cell takes focus as its row appears, ready to edit
openableboolean—Each row gets an open button, and Enter on a read-only title opens it
resizableboolean—Column edges can be dragged, or moved with Alt+Arrow keys on a header; each asks for a new view
addColumnstring—A "+" header after the last column, emitting RequestedAddColumn: its label, "Add a field"
columnActionsItemAction[]—A menu on each header ("Edit field", "Delete field"), emitting RequestedColumnAction
hideableboolean—A "Hide field" entry in each field's column menu, asking for a view with the field hidden
freezableboolean—A "Freeze up to here" entry in each field's column menu, asking for a view with frozen set
movableboolean—Field headers can be dragged to a new place, or moved with Alt+Shift+Arrow keys; each asks for a new view
readOnlystring—Why nothing here can be edited: "You can view this table, not edit it"
loadingboolean—Show placeholder rows while the records load
empty{ title, hint }—What the grid says when there are no records: a title and a hint
outcomesOutcome[]—How each requested change settled: pending, accepted, or refused with a reason
noticestring | null—A sentence about the last bulk action or a table-level refusal
rowHeightnumber32A row's height in pixels; 32 by default
localestring—The locale numbers and dates are formatted in; the browser's by default

Events

Table events
EventPayloadDescription
RequestedEdit{ request: string; item: string; key: string; value: Value }A value the person changed; answer through outcomes with the same request
RequestedOpen{ item: string }Open the record's page
RequestedCreate{ group?: string; title?: string; values?: Record<string, Value> }A new record, in the group it was added from ("" for the empty group)
RequestedAction{ action: string; items: string[] }One of the view's actions, on these records
RequestedReorder{ item: string; before: string | null }Move item before before, or last when it's null
RequestedView{ view: View }The person changed how the view shows records (its sort, grouping, widths); pass it back as view
Selected{ items: string[] }The selection changed
RequestedCellAction{ item: string; key: string; action: string }A cell's button: "Run agent", "Retry", a button field's press
RequestedAddColumn{}The "+" header was pressed: open a field editor to add a field
RequestedColumnAction{ key: string; action: string }One of columnActions on a column (title for the first)

Agent actions

What agents can do with Table
ActionDescription
CommittedEditSet one cell. key: a column key (or title when it's editable). value: an option value, a list of them, text, a number, an ISO date, true/false, or null to clear
ClickedCellActionPress a cell's button, such as Run agent or Retry (see the cell's action in the page)
RequestedSelectionSelect rows by id, replacing the selection ([] clears it)
ClickedActionRun one of the table's actions on the selected rows; destructive ones name the selection as the target
ClickedSortOrder the rows by a column key (or title), asc or desc, replacing the view's sort; direction null drops it
ActivatedRowOpen a row
ClickedCreateAdd a row
ClickedAddColumnStart adding a column
ClickedColumnActionRun one of a column's actions (key: a column key, or title); destructive ones name the column
ClickedHideColumnHide a field's column from this view (key: a field key)
ClickedPeekShow a row's fields in Peek, beside the grid
ClosedPeekClose Peek

Wiring it to your app

The grid handles the active cell, selection and showing an edit before it saves. Handle RequestedEdit with an app command, and reply through outcomes with the request's ID.

On success, pass the saved row with an Accepted outcome. On refusal, pass a Refused outcome with the reason and leave the row unchanged. Edits from people and agents can share the same command and rules.

View a complete app example
import { Command, UiSchema } from "effect/ui"import { Html } from "effect/ui/html"import { Effect, Schema } from "effect"import { Outcome, type Property, Value } from "./ui/uicontext/components/Property.ts"import { Table } from "./ui/uicontext/components/Table.ts"const Status = Schema.Literals(["Ready", "Paused"])const isStatus = Schema.is(Status)const Workflow = Schema.Struct({ id: Schema.String, name: Schema.String, status: Status })const Edit = { request: Schema.String, item: Schema.String, key: Schema.String, value: Value }const SaveResult = Schema.Union([	Schema.TaggedStruct("Saved", { status: Status }),	Schema.TaggedStruct("Refused", { reason: Schema.String }),])export class SaveWorkflow extends Command.Service<SaveWorkflow>()("recipe/SaveWorkflow", {	args: Edit,	success: SaveResult,	mode: "queue",	group: ["item"],}) {	static readonly layer = this.toLayer(({ item, key, value }) =>		Effect.sleep("350 millis").pipe(Effect.map(() => {			if (key !== "status" || !isStatus(value)) {				return { _tag: "Refused", reason: "Enter Ready or Paused." }			}			if (item === "billing" && value === "Paused") {				return { _tag: "Refused", reason: "Billing sync must stay ready." }			}			return { _tag: "Saved", status: value }		})),	)}const Message = UiSchema.TaggedEnum({	RequestedEdit: Edit,	SavedEdit: { request: Schema.String, item: Schema.String, result: SaveResult },	RequestedArchive: { items: Schema.Array(Schema.String) },})const properties: ReadonlyArray<Property> = [{ key: "status", label: "Status", kind: "text" }]const archive = [{ id: "archive", label: "Archive selected", consequential: true }] as constexport const Workflows = Html.component({	name: "WorkflowStatus",	model: Schema.Struct({		workflows: Schema.Array(Workflow),		pending: Schema.Array(Schema.String),		outcomes: Schema.Array(Outcome),		notice: Schema.String,	}),	message: Message,}).make({	init: () => ({		workflows: [			{ id: "digest", name: "Daily digest", status: "Ready" },			{ id: "billing", name: "Billing sync", status: "Ready" },		],		pending: [],		outcomes: [],		notice: "Changes are kept until you reload this page.",	}),	update: {		RequestedEdit: ($, { request, item, key, value }) =>			$.evolve({ pending: (pending) => [...pending, request] })				.run(Command.map(					SaveWorkflow.make({ request, item, key, value }),					(result) => Message.SavedEdit({ request, item, result }),				)),		SavedEdit: ($, { request, item, result }) => {			if (!$.model.pending.includes(request)) return $.model			const saved = result._tag === "Saved"			return $.evolve({				workflows: saved					? $.model.workflows.map((workflow) => workflow.id === item ? { ...workflow, status: result.status } : workflow)					: $.model.workflows,				pending: (pending) => pending.filter((id) => id !== request),				outcomes: (outcomes) => [...outcomes, saved ? { _tag: "Accepted" as const, request } : { _tag: "Refused" as const, request, reason: result.reason }],				notice: saved ? "Status saved." : "Status left unchanged.",			})		},		RequestedArchive: ($, { items }) => {			if ($.model.pending.length !== 0) return $.model			return $.evolve({				workflows: (workflows) => workflows.filter(({ id }) => !items.includes(id)),				notice: "Selection archived.",			})		},	},	view: (h, model) => {		const items = model.workflows.map(({ id, name, status }) => ({ id, title: name, values: { status } }))		return h.section.attr("aria-labelledby", "workflow-heading").children(			h.header.children(				h.h2.attr("id", "workflow-heading").children("Workflow status"),				h.p.children("Press Enter on a status to edit it. Try pausing Billing sync to see a refused save."),			),			h.div.attr("class", "table").children(				Table(h, {					key: "workflows",					props: {						agentId: "workflows",						label: "Workflows",						title: { label: "Workflow", width: 176 },						view: { widths: { status: 160 } },						rowHeight: 40,						records: items,						fields: properties,						outcomes: model.outcomes,						actions: model.pending.length === 0 ? archive : [],					},					onEmit: {						RequestedEdit: (edit) => Message.RequestedEdit(edit),						RequestedAction: ({ action, items }) => action === "archive" ? Message.RequestedArchive({ items }) : undefined,						RequestedOpen: () => undefined,						RequestedCreate: () => undefined,						RequestedReorder: () => undefined,						RequestedView: () => undefined,						RequestedCellAction: () => undefined,						RequestedAddColumn: () => undefined,						RequestedColumnAction: () => undefined,						Selected: () => undefined,					},				}),			),			h.p.attrs({ class: "feedback", role: "status" }).children(				model.pending.length > 0 ? "Saving changes…" : model.notice,			),		)	},})
workflows.ts on GitHub

Keyboard and accessibility

KeysDoes
Up arrow Down arrow Left arrow Right arrowMove between cells, the header row included
Alt Left arrow Alt Right arrowOn a header, narrow or widen the column
Enter F2Edit the cell, or type to replace it; Escape cancels and Tab saves and moves
Shift Down arrow Shift Right arrowStretch a range of cells; Shift+click or drag does too
Control C Control VCopy or paste cells as tab-separated text; one value pasted fills the range
Control DFill down from the range's top row, or from the row above
DeleteClear the cell or the range
Control Z Control Shift ZUndo or redo your last change
Alt Shift Right arrowMove a column, on its header
J Down arrowNext record
K Up arrowPrevious record
Shift J Shift KExtend the selection
XSelect or unselect
SpacePeek at the record; Escape closes it
EnterOpen the record
EscapeClear the selection
S P AOpen the picker for a field the app gives a shortcut, on the focused or selected records

On a Mac, Ctrl is ⌘ and Alt is ⌥. Left and Right trade places in right-to-left text.

  • A grid: arrow keys move between cells and headers, Enter or F2 edits, typing starts an edit, Escape cancels, Tab saves and moves on.
  • Mod+C copies the selected cells, and pasting tab-separated text fills a block.
  • Shift+F10 on a header opens its column actions; Alt+Left and Alt+Right resize a column.
  • A refused edit puts the old value back and says why.
  • A cell that can't be edited is read-only, and says why as its description and in a tip under it while it has focus, by keyboard or touch.

Installation

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

Source