Skip to content

Data grid

Pro

Spreadsheet-style editing, virtualized both ways, with typed editors, validation, keyboard ranges, and copy and paste. Not an M3 component (@windmorph/react-pro).

import { DataGrid } from '@windmorph/react-pro/data-grid';

Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.

Props

By name or description, across the 32 props below

DataGrid 32 props

  • columnstype readonly DataGridColumn<Row>[]Required

    The columns.

  • rowstype readonly Row[]Required

    Every row; only those in view are rendered.

  • getRowIdtype (row: Row) => stringRequired

    A row's unique id.

  • getValuetype ((row: Row, column: DataGridColumn<Row>) => ColumnValue)default the column's accessor

    Reads a cell's value.

  • editabletype booleandefault false

    Whether cells can be edited, unless a column says otherwise.

  • getCellStatetype ((row: Row, column: DataGridColumn<Row>) => DataGridCellState | null)

    A cell's semantic state, with the label that keeps colour from being alone.

  • rowHeadertype ((row: Row, index: number) => ReactNode)

    Content of a row header column, joined to the grid's movement; Enter reaches its controls.

  • summaryRowstype readonly DataGridSummaryRow[]

    Rows of totals the app worked out, kept at the bottom.

  • selectiontype DataGridSelection | null

    The selected range (controlled).

  • defaultSelectiontype DataGridSelection | null

    The range selected at first (uncontrolled).

  • rowHeighttype numberdefault the row-height token

    A row's height at density 0, px.

  • heighttype string | numberdefault 480

    The scrolling area's height.

  • overscantype numberdefault 4

    Rows and columns rendered beyond those in view.

  • densitytype 0 | -1 | -2 | -3default the theme's

    The grid's own density.

  • loadingtype booleandefault false

    Shows loading rows.

  • emptytype ReactNodedefault an EmptyState with labels.empty

    Shown when there are no rows.

  • errortype ReactNode

    A message to show in place of the rows.

  • iconstype Partial<DataGridIcons>

    Replaces icons.

  • reftype Ref<HTMLDivElement>

    Ref to the outermost element.

  • idtype string

    The outermost element's id.

Events

  • onCellChangetype ((change: DataGridCellChange<Row>) => void)

    Called when a cell's value is committed and valid.

  • onSelectionChangetype ((selection: DataGridSelection | null) => void)

    Called when the selected range changes.

  • onPastetype ((cells: DataGridPastedCell<Row>[]) => boolean | void | DataGridPastedCell<Row>[])

    May reject a paste (false) or return the changes to apply instead.

  • onRetrytype (() => void)

    Adds a retry button to the error.

Text

  • labelstype Partial<DataGridLabels>

    Words it shows or announces. A LabelsProvider sets them for the whole app.

  • aria-labeltype string

    One of aria-label or aria-labelledby is required.

  • aria-labelledbytype string

    One of aria-label or aria-labelledby is required.

  • aria-describedbytype string

    The id of an element that describes it.

  • aria-detailstype string

    The id of an element with more detail about it.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

Types

DataGridColumn 24 fields

A column of a DataGrid: DataTable's column definition, plus editing and pinning.

  • widthtype numberdefault 140

    Width, px. The grid renders only the rows in view, so it has no 'fit': it can't measure the rest.

  • editortype DataGridEditor<Row>default a text or number field, by type

    How the column is edited.

  • validatetype (value: ColumnValue, row: Row) => string | false | null | undefined

    Returns a message when a value isn't acceptable, or false for labels.invalidValue.

  • editabletype boolean | ((row: Row) => boolean)default the grid's editable

    Whether its cells can be edited.

  • pinnedtype "start" | "end"

    Keeps the column in view at the grid's start or end.

  • currencytype stringdefault "USD"

    With type="currency", the ISO 4217 code.

  • idtype stringRequired

    Unique within the table.

  • headertype stringRequired

    Shown above the column and in column settings. Never empty: screen readers name it.

  • accessortype (row: Row) => ColumnValueRequired

    The value used to sort, search, filter and display by default.

  • celltype (row: Row) => React.ReactNodedefault the formatted accessor value

    Custom cell content.

  • typetype ColumnTypedefault "text"

    Formats the value when there is no cell, right-aligning numbers.

  • formattype (value: ColumnValue, row: Row) => string

    Replaces the type's formatting.

  • aligntype "start" | "center" | "end"default "end" for numbers and currency, else "start"

    Alignment of the header and cells.

  • minWidthtype numberdefault 80

    Least width, px.

  • maxWidthtype number

    Greatest width, px.

  • growtype booleandefault false

    Shares the table's spare width in proportion to its width.

  • rowHeadertype booleandefault true for the first column, when none is set

    Announced with each row.

  • sortabletype booleandefault true, or false in plain

    Whether a press on the header sorts.

  • hideabletype booleandefault true

    Whether people can hide it.

  • pinnabletype booleandefault true

    Whether people can pin it.

  • reorderabletype booleandefault true

    Whether people can reorder it.

  • resizabletype booleandefault true

    Whether people can resize it.

  • filtertype ColumnFilter

    How people filter it, if they can.

  • searchabletype booleandefault true while it is shown, false while hidden

    Whether search reads it.

DataGridSelection 2 fields

A selected range of cells.

  • anchortype DataGridCellPositionRequired

    Where the range started.

  • focustype DataGridCellPositionRequired

    Where the range ends.

DataGridCellChange 4 fields

A cell's changed value, as DataGrid's onCellChange reports it.

  • rowtype RowRequired

    The row.

  • rowIdtype stringRequired

    The row’s id.

  • columnIdtype stringRequired

    The column’s id.

  • valuetype ColumnValueRequired

    The new value.

DataGridCellState 2 fields

A cell's state: never colour alone, so it carries a label.

  • statetype stringRequired

    changed, warning, error, info, or an app's own name (data-state).

  • labeltype stringRequired

    Says what the state means, to people and to assistive technology.

DataGridSummaryRow 3 fields

A row of totals the app worked out; the grid never computes.

  • idtype stringRequired

    Unique among the summary rows.

  • labeltype string | number | bigint | boolean | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal | Promise<AwaitedReactNode>

    Shown in the row header cell.

  • valuestype Record<string, React.ReactNode>Required

    What each column shows, by column id.

DataGridPastedCell 5 fields

What onPaste gets, and may change.

  • texttype stringRequired

    The text that was pasted into the cell.

  • rowtype RowRequired

    The row.

  • rowIdtype stringRequired

    The row’s id.

  • columnIdtype stringRequired

    The column’s id.

  • valuetype ColumnValueRequired

    The new value.

Spec status

Not part of Material Design 3: a Windmorph Pro component, built on M3's colour roles, type scale, shapes and motion. Its variants and configurations each link to a live example.

  • Typed editors, validation and copy and paste (editable, validate)

    Built

    Configuration · Editing

  • Row headers, pinned columns and totals (rowHeader, summaryRows)

    Built

    Configuration · Summary

Theming & tokens

Set the tokens below on the grid or any ancestor. Its editors are the core's fields, which keep their own tokens. Style each part with classNames: root, scroller, header, headerRow, headerCell, rowHeaderCell, body, row, cell, editor, invalidIcon, summaryRow, summaryCell, status, loading, empty, error.

DataGrid tokens
VariableDefaultPaints
--wm-data-grid-container-colorvar(--md-sys-color-surface)The grid’s surface, and a cell at rest.
--wm-data-grid-container-shapevar(--md-sys-shape-corner-medium)The scrolling area’s corners.
--wm-data-grid-outline-colorvar(--md-sys-color-outline-variant)The line around the scrolling area.
--wm-data-grid-header-height56pxThe header’s height at density 0; each density step takes 4px off.
--wm-data-grid-header-colorvar(--md-sys-color-surface-container)The header’s surface.
--wm-data-grid-header-text-colorvar(--md-sys-color-on-surface-variant)The header’s text.
--wm-data-grid-row-height48pxA row’s height at density 0; each density step takes 4px off.
--wm-data-grid-row-text-colorvar(--md-sys-color-on-surface)A cell’s text.
--wm-data-grid-row-header-width64pxThe width of the row header column.
--wm-data-grid-divider-colorvar(--md-sys-color-outline-variant)The lines between cells.
--wm-data-grid-cell-padding12pxThe space at a cell’s sides.
--wm-data-grid-active-outline-colorvar(--md-sys-color-secondary)The outline of the active cell.
--wm-data-grid-active-outline-width2pxThe width of the active cell’s outline.
--wm-data-grid-selection-colorvar(--md-sys-color-secondary-container)A selected cell’s fill.
--wm-data-grid-editor-colorvar(--md-sys-color-surface-container-highest)The fill behind a cell’s editor.
--wm-data-grid-selection-text-colorvar(--md-sys-color-on-secondary-container)A selected cell’s text.
--wm-data-grid-state-changed-text-colorvar(--md-sys-color-on-tertiary-container)The text of a cell in the `changed` state.
--wm-data-grid-state-warning-text-colorvar(--md-sys-color-on-warning-container)The text of a cell in the `warning` state.
--wm-data-grid-state-error-text-colorvar(--md-sys-color-on-error-container)The text of a cell in the `error` state.
--wm-data-grid-state-info-text-colorvar(--md-sys-color-on-surface)The text of a cell in the `info` state.
--wm-data-grid-invalid-colorvar(--md-sys-color-error)An invalid cell’s text and icon.
--wm-data-grid-state-changed-colorvar(--md-sys-color-tertiary-container)The fill of a cell in the `changed` state.
--wm-data-grid-state-warning-colorvar(--md-sys-color-warning-container)The fill of a cell in the `warning` state.
--wm-data-grid-state-error-colorvar(--md-sys-color-error-container)The fill of a cell in the `error` state.
--wm-data-grid-state-info-colorvar(--md-sys-color-surface-container-high)The fill of a cell in the `info` state.
--wm-data-grid-pin-shadow-colorcolor-mix(in srgb, var(--md-sys-color-shadow) 25%, transparent)The shadow a pinned column casts over what scrolls under it.
--wm-data-grid-pin-shadow-size4pxThe reach of a pinned column’s shadow.
--wm-data-grid-summary-colorvar(--md-sys-color-surface-container)A summary row’s surface.
--wm-data-grid-summary-text-colorvar(--md-sys-color-on-surface)A summary row’s text.
--wm-data-grid-status-gap8pxThe space between the grid and its message.
--wm-data-grid-status-min-height20pxThe least height of the message below the grid.
--wm-data-grid-icon-gap4pxThe space before a cell’s icon.
--wm-data-grid-icon-size16pxA cell’s icon.
--wm-data-grid-loading-padding16pxThe space around loading rows.
--wm-data-grid-skeleton-gap8pxThe space between loading rows.
--wm-data-grid-skeleton-height32pxA loading row’s height.
--wm-data-grid-state-padding32pxThe space above and below the empty and error states.