Spreadsheet
Preview

Build read-only or editable spreadsheet-style DataGrids with cell selection, fill, and keyboard navigation.

Overview

Set interaction="spreadsheet" when cells, rather than rows, own pointer and keyboard interaction. The preset supports both read-only spreadsheets and editable grids while preserving consumer-owned records and column definitions.

CapabilityDataGrid ownsConsumer owns
Cell selectionRange identity, pointer/keyboard interaction, selected stylingWhich columns may be selected and what product actions selection enables
Fill requestsFill handle and source/target range requestFill algorithm, parsing, validation, and record mutation
NavigationRoving tab stop, arrow-key movement, focus visibilityWhen product UI requests focus imperatively
EditingEdit identity, activation, and editor boundariesEditors, drafts, validation, mutations, and persistence

Cell selection is distinct from the Row Selection preset. Opt checkbox or action columns out of cell selection with enableCellSelection: false.

Examples

Cell selection

Users can click, drag, Shift-extend, or use the keyboard to select a rectangular range. DataGrid suppresses browser text selection during drags that begin on selectable cells, while interactive cell content retains its normal behavior.

Fill requests

Passing onFillRequest enables the fill handle for the active range. DataGrid reports stable row and column IDs; it never copies or mutates record values.

Keyboard navigation

The viewport owns one roving tab stop. Arrow keys move through selectable cells and skip columns where cell.getCanSelect() is false. Home and End stay within the current row; Ctrl or Command with Home or End moves to the first or last selectable cell. Escape clears the current cell selection and returns DOM focus to the viewport, removing the active cell without moving focus outside the grid.

Imperative focus

Use the viewport handle when another product control must move focus into a known cell. Identify cells with stable consumer row and column IDs.

Editing

Editing is optional within the spreadsheet preset. DataGrid identifies the active cell, resolves whether it may enter edit mode, and provides editor chrome and interaction boundaries. The consumer owns drafts, parsing, validation, record updates, persistence, optimistic behavior, permissions, and error recovery.

Editability resolves from the most specific configured level:

  1. A column enableEditing value or predicate overrides the table default.
  2. Otherwise the table enableEditing value or predicate applies.
  3. Synthetic grouped, aggregate, pivot, subtotal, and total cells are read only.

Editable cells enter edit mode through double-click, Enter, F2, printable typing, or an explicit cell.startEditing() call. Escape stops editing. A consumer capture handler may call preventDefault() to reserve an interaction.

Basic editing

Enable editing at table level, render a consumer-owned editor in the editable column, and commit changes into consumer state.

Subscribe to table.atoms.editingCell inside the editor so only cells that depend on editing state update:

function EditableTextCell({ cell, onCommit }) {
  return (
    <Subscribe
      source={cell.table.atoms.editingCell}
      selector={(editing) =>
        editing?.rowId === cell.row.id && editing.columnId === cell.column.id
      }
    >
      {(isEditing) =>
        isEditing ? (
          <DataGrid.Editor>
            <Input /* consumer draft and commit handlers */ />
          </DataGrid.Editor>
        ) : (
          cell.getValue()
        )
      }
    </Subscribe>
  );
}

Edit eligibility

This table is read only by default. Its Owner column opts in only for rows whose status is Review, demonstrating the table default, column override, and per-cell predicate without mixing in validation.

Validation

Eligibility decides whether an editor may open. Validation is a separate consumer concern in the commit path. Return false when validation fails to leave the editor open; return true after applying the accepted value.

Editing state

FieldTypeDescription
rowIdstringStable row ID of the active cell.
columnIdstringColumn ID of the active cell.
reason"consumer" | "double-click" | "enter" | "f2" | "typing"Interaction that started editing.
initialTextstring | undefinedFirst printable character for type-to-replace behavior.

API Reference

DataGrid props

PropTypeDefaultDescription
interaction"spreadsheet"-Enables cell focus, selection, range gestures, and optional editing activation. Required.
onFillRequest(request: DataGridFillRequest) => void-Enables the fill handle and reports the requested source and target ranges.

Table options

OptionTypeDefaultDescription
autoResetCellSelectionbooleantrueResets cell selection when the data reference changes.
enableCellSelectionboolean | ((cell) => boolean)trueEnables selection globally or for cells that match a predicate.
enableCellRangeSelectionbooleantrueEnables Shift and drag range selection.
enableCellSelectionDragbooleantrueEnables extending a range by dragging.
enableMultiCellRangeSelectionbooleantrueEnables modifier-key include and exclude ranges.
isCellRangeSelectionEvent(event: unknown) => booleanShift-key eventDetermines whether a selection gesture extends the active range.
isMultiCellRangeSelectionEvent(event: unknown) => booleanControl- or Command-key eventDetermines whether a gesture adds or subtracts a range.
onCellSelectionChangeOnChangeFn<CellSelectionState>State updaterReceives cell-selection updates when the consumer controls the slice.

Column options

OptionTypeDefaultDescription
enableCellSelectionbooleantrueAllows cells in the column to be selected.

Selection methods

APISignatureDescription
table.getFocusedCell() => Cell<DataGridFeatures, TData> | undefinedReturns the active cell.
table.getSelectedCellCount() => numberReturns the number of selected cells.
table.getSelectedCellRangesData() => unknown[][][]Returns each selected region's values as a row-major grid.
table.selectCellRange(range, options?) => voidReplaces, includes, or excludes a rectangular range.
table.selectAllCells() => voidSelects every eligible cell.
table.setFocusedCell(rowId, columnId) => voidCollapses selection to one cell address.
table.resetCellSelection(defaultState?) => voidRestores initial selection, or clears it when passed true.

DataGridCellAddress

FieldTypeDescription
rowIdstringStable consumer row ID.
columnIdstringStable column ID.

DataGridFillRequest

FieldTypeDescription
sourceCellSelectionRangeActive range before the fill gesture.
targetCellSelectionRangeRequested range after the fill gesture.

Each range stores anchor and focus row and column IDs. Apply the request to consumer records only after product validation.

DataGridViewportHandle

MethodSignatureDescription
focusCell(address: DataGridCellAddress) => voidFocuses and reveals a selectable cell, mounting its virtual row when needed. Invalid or ineligible addresses do nothing.
scrollToCell(address: DataGridCellAddress, options?) => voidReveals a cell and mounts its virtual row when needed. options.align accepts "auto", "center", "end", or "start".

Subscribe to table.atoms.cellSelection when another product control needs the current range.

Table editing options

OptionTypeDefaultDescription
enableEditingboolean | ((cell) => boolean)falseEnables editing for every eligible cell or cells that match a predicate.
onEditingCellChangeOnChangeFn<DataGridEditingState>State updaterReceives editing-state updates when the consumer controls the slice.

Column editing options

OptionTypeDefaultDescription
enableEditingboolean | ((cell) => boolean)Table settingOverrides edit eligibility for cells in the column.

Editing cell methods

MethodSignatureDescription
cell.getCanEdit() => booleanReturns whether the cell can enter edit mode. Synthetic cells are always read only.
cell.getIsEditing() => booleanReturns whether the cell is currently editing.
cell.startEditing(details?) => voidRequests edit mode when the cell can edit.
cell.stopEditing() => voidClears edit mode when the cell is active.

Editing table methods

MethodSignatureDescription
table.setEditingCell(updater) => voidSets or updates editing identity.
table.resetEditingCell(defaultState?) => voidRestores initial editing state, or clears it when passed true.

DataGrid.Editor

Visual chrome and event isolation for a consumer-owned editor. It extends div props and does not own draft or commit behavior.

On this page