Skip to content
GitHub (opens in a new tab)

DataGrid

An editable table: people click a cell to add or change its content, like rule conditions, line items, or mappings. It validates cells, can total the valid rows, and stacks below 30rem.

stableOrganismcontracts/datagrid.json

Preview

DataGrid

An editable table: people click a cell to add or change its content, like rule conditions, line items, or mappings. It validates cells, totals the valid rows, and stacks below 30rem.

Master

Click a cell or press Enter to edit. Condition is kit Select. Add and remove rows.

FieldConditionValueRemove

Usage

DataGrid for in-place edits. Table for a short read-only list. DataTable for search, filters, and selection. Do not put a Field and Input on every row.

Do's

  • People build or change rows in place: rule conditions, price tiers, field mappings, line items
  • Short editable lists where a form per row would be slow

Don'ts

  • Short read-only text rows — use Table
  • Searchable, filterable datasets people read and select — use DataTable
  • One primary/secondary line — use ListView
  • A form of Fields and Inputs per row
<DataGrid
  label="Conditions"
  columns={[
    { key: "field", header: "Field" },
    {
      key: "condition",
      header: "Condition",
      type: "select",
      options: conditions,
      width: "12rem",
    },
    { key: "value", header: "Value" },
  ]}
  rows={rules}
  onRowsChange={setRules}
  canAddRows
  canRemoveRows
/>

When to use

  • People build or change rows in place: rule conditions, price tiers, field mappings, line items
  • Short editable lists where a form per row would be slow

When not to use

  • Short read-only text rows — use Table
  • Searchable, filterable datasets people read and select — use DataTable
  • One primary/secondary line — use ListView
  • A form of Fields and Inputs per row

What an agent reads

import { DataGrid } from "agentic-ds-kit";
must
  • Native table named by label, with kit HeaderCell headers and th scope=col
  • Each idle text cell is a button named by its column and row with its value, like Value, row 2: 100
  • Select and date columns always show the kit Select or DatePicker in the cell so the grid does not shift when the value changes
  • Enter or click on a text cell opens a kit Input named the same way, inset in the cell, and focus moves into it
  • Enter saves and Escape cancels; focus goes back to the cell. Tab moves to the next cell
  • Remove row buttons are named Remove row 2 and show that in a Tooltip
  • A date cell editor is a kit DatePicker named by its column and row, like Start date, row 2
  • Empty state is one td with colSpan holding a small kit Empty with emptyLabel
  • Number and money cells are end-aligned with tabular figures
  • A computed cell is plain read-only text, not a button; on a row with an invalid cell it shows an em dash
  • An invalid cell gets a danger ring and an icon on that cell only, aria-invalid, and aria-describedby pointing at its message ("Qty, row 3: enter 1 or more · left out of the total") in the row under it
  • Rows with an invalid cell are left out of totals; errorSummary is a role status line
  • Totals sit in tfoot with th scope=row labels
  • Below 30rem of grid width the grid stacks: each row is a button with aria-expanded that opens labelled fields; an invalid row starts open with its message under the field
  • Wider than that but still narrow, the table keeps column min-width and scrolls horizontally; the scroller is a focusable region
  • Focus uses the kit ring
defaults
  • label Data grid
  • size md
  • canAddRows false
  • canRemoveRows false
  • emptyLabel No rows yet.
  • rowNumbers false
  • stickyFirstColumn false
  • errorSummary false
stops if
  • Do not invent EditableCell, GridRow, or a table of loose Inputs. Pass columns with a type.
  • Do not wrap the grid in Form. Save the rows from onRowsChange.
  • Search, filters, column settings, sort, or bulk selection — use DataTable
  • Short read-only text rows — use Table
  • One primary/secondary line — use ListView
  • Do not use Cell for editable body cells — Cell is display content for DataTable
  • Do not add type formula. A computed column (compute) is allowed; there is no FormulaEditor. Stop and ask for anything more.
  • Do not use raw hex
  • Do not add Density or expandable row detail. Rows open only when the grid stacks below 30rem, to edit that row
  • Do not make Add row a primary Button
  • Do not colour a whole row for one invalid cell; mark the cell

From contracts/datagrid.json: must is the a11y requirements, defaults the prop defaults, stops if the doNot rules where the agent asks instead of inventing a cousin.

Props

NameTypeRequiredDefaultNotes
columnsarrayYes—type defaults to text. select needs options. date is kit DatePicker; value is YYYY-MM-DD. number and money are end-aligned with tabular figures and hold decimal strings ("18", "39.00"); money shows them in currency (default USD). compute makes a derived, read-only column such as Amount = Qty × Unit price; it is not a formula editor. validate returns a short fix ("enter 1 or more") or undefined. Do not add type formula: there is no FormulaEditor; a computed column is the only derived value.
rowsarrayNo—Controlled rows, one string per column key. Save with onRowsChange. Do not wrap the grid in Form.
defaultRowsarrayNo—Starting rows when rows is not controlled.
onRowsChangefunctionNo—(rows: DataGridRow[]) => void. Runs when a cell is saved and when rows are added or removed.
labelstringNoData gridAccessible name for the table, and each cell, like Value, row 2.
sizesm | mdNomdPassed to HeaderCell. Edit controls are size sm.
canAddRowsbooleanNofalseAdd row button under the grid. Not primary. New row starts empty; first cell opens for editing (when stacked, the row opens).
canRemoveRowsbooleanNofalseRemove control at the end of each row. Named in a kit Tooltip.
emptyLabelstringNoNo rows yet.Shown in one td with colSpan when there are no rows.
rowNumbersbooleanNofalseA # column with each row's number.
stickyFirstColumnbooleanNofalseThe # column (if shown) and the first data column stay in place while the grid scrolls sideways.
totalsfunctionNo—(validRows) => { label, value, emphasis?, narrowLabel? }[]. Footer lines worked out from rows with no invalid cell, e.g. Subtotal, VAT 20%, Total. Values are pre-formatted. The emphasised line is the grand total and the only one shown when the grid stacks, with narrowLabel ("Total incl. VAT").
errorSummarybooleanNofalseA status line above the grid: "1 line needs a fix" / "3 lines need a fix". Empty when every row is valid.
  • Component
    →

    Table

    Simple semantic table for invoices, lists, and text rows, with optional sort, row menu, sticky header, loading, empty and error states, row dividers on or off, and one optional highlighted row.

  • Component
    →

    DataTable

    Framed dataset with search, filters, column settings, and a caption title.

  • Component
    →

    ListView

    A list of records, one row each: primary and optional secondary line, leading avatar or icon, trailing value, badge, actions, or chevron.

  • Component
    →

    HeaderCell

    Column header for DataTable: label, optional select-all checkbox, optional sort, sm or md.