SpreadsheetGrid
Guides

Selection and clipboard

Cell range selection, row selection (checkboxes), and the rules for copy and paste that round-trip with Excel

The grid has two kinds of selection: the cell range selection that selects cells (as in Excel; what copy, paste and clear work on), and the row selection with the checkboxes at the start of rows (enableRowSelection; what your app's actions such as "Delete the selected rows" work on). They are separate: changing one doesn't change the other.

Demo (order entry)

Ctrl/Cmd+Z undoes the delete
Rows 5 of 5Columns 4 of 4Sort: —
Rows 5 of 5Columns 4 of 4
Cell —Range —0 cells / 0 rows0 columns
  • Press a cell and drag, or use Shift+Arrow, to select a range, and copy it with Ctrl/Cmd+C. A dotted line runs around the copied range (Esc removes it).
  • Copy the text of "Sample to paste" above, select a cell and paste it with Ctrl/Cmd+V. Rows that spill past the end of the table are added with createRow.
  • Select rows with the checkboxes at the start of the rows and press "Delete the selected rows" to remove them. Ctrl/Cmd+Z brings them back (because they are passed through the handle's applyRows).
  • Select 2 or more cells and the bottom bar shows the average / count / sum.

Cell range selection

ActionWhat gets selected
Press a cellThat cell (it becomes the active cell)
Press a cell and drag / Shift+ArrowA range (dragging near an edge scrolls automatically)
Shift+press a cellFrom the anchor of the current range (or the active cell) to the pressed cell
Press a row number / Shift+pressThat row / from the anchor row to the pressed row
Press a column headerThat column (Shift+press adds the column to the sort instead of selecting)
Ctrl/Cmd+AEverything (press again to clear)
EscapeClear the range
  • With enableRangeSelection={false}, only the pressed cell is selected (no ranges).
  • On touch devices, a tap selects a cell and a swipe scrolls (range selection isn't available).
  • Read the selected range with the handle's getSelection(). It returns one of { type: 'cell', range } / { type: 'row', startRow, endRow } / { type: 'col', startCol, endCol } / null, and positions are view positions after sorting and filtering. The data of the rows in the range is getSelectedRows().
  • To select from code, use selectCell(viewRowIndex, colIndex) / selectRange(range) / clearSelection(). They don't move focus, so call focus() too if you want the grid to receive keys next. To get positions from row keys or column keys, use getViewRowIndex(rowKey) / getColIndex(columnKey).
  • There is no prop that notifies selection changes. Changes of the active cell come through onActiveCellChange, and ctx.selection in your own bars (renderTopBar / renderBottomBar) holds the current range.

Selection aggregates

Select 2 or more cells and the right side of the bottom bar shows the average / count / sum (like Excel's status bar. On by default; showSelectionAggregates={false} hides it). It counts the cells of visible data rows × data columns, and the sum and average use only numbers and numeric strings. Large ranges are counted in time slices, and a "calculating" message shows meanwhile. Columns of digit strings that aren't numbers, such as JAN codes, postal codes or employee numbers, can be left out of the sum and average with the column's selectionAggregate: false (they still count toward the count. Since 1.2.0). Select editor columns are also counted by value, so columns whose values (codes) are digit strings ('10' / '8') go into the sum and average even when the cells show display names ("Tax 10%"). Give those columns selectionAggregate: false too.

Row selection (checkboxes)

<SpreadsheetGrid
  rows={rows}
  columns={columns}
  rowKeyGetter={(row) => row.id}   // row selection is remembered by row key
  enableRowSelection
  onRowSelectionChange={() => setCount(gridRef.current?.getSelectedRowCount() ?? 0)}
  ref={gridRef}
/>
  • With enableRowSelection, the row number column becomes checkboxes. In multiple selection (the default rowSelectionMode="multiple"), each press toggles, and Shift+press or dragging selects a range. 'single' always selects one row.
  • The checkbox at the top left selects all (enableSelectAllRows). While a filter hides rows, it selects / clears only the visible rows. To select the hidden rows too, use the handle's selectAllRows(). In tree data it covers all rows the filter matched, including rows inside closed parents (parents that don't match are not included).
  • Read the selected rows with the handle's getSelectedRowKeys() / getSelectedRowData() / getSelectedRowCount() / isRowSelected(rowKey). Calling them inside onRowSelectionChange returns the new selection.
  • To hold the selection yourself, pass rowSelection ({ type: 'include', rowKeys }, or { type: 'exclude', rowKeys } = select all except) or the simpler selectedRowKeys, and feed back the value you receive in onRowSelectionChange.
  • With serverSide (dataSource), getSelectedRowKeys() / getSelectedRowData() return only loaded rows.
  • When you remove selected rows from rows, their keys leave the selection and onRowSelectionChange is called (since 1.3.0. Keys you passed before the rows were loaded stay). Restoring the removed rows doesn't restore the selection.

Copy (Ctrl/Cmd+C)

Writes the selected range to the clipboard as TSV (tab-separated). It pastes straight into Excel and Google Sheets.

  • Values are raw values (not passed through valueFormatter; 1234.5 is 1234.5, not 1,234.5). For columns you want copied as shown on screen, write the same formatting in the column's formatClipboardValue. Select editor columns with clipboard: 'label' copy the display name (label) instead of the option's value (code) (since 1.1.0. Pasted display names are read back as values; see Values and labels).
  • Cells containing line breaks, tabs or " are wrapped in "…", and " becomes "" (as in Excel). If every cell of the last row is empty, a trailing line break is added (the same shape as Excel, so pasting doesn't drop the last empty row).
  • Not copied: label rows, group rows, the row drag handle column / detail toggle column / auto group column (no empty columns in the TSV), and rows for which isRowExportable returns false.
  • After copying, a dotted line runs around the copied range (showCopyRange, on by default). Escape and starting an edit remove it.
  • To paste into Excel or an email as a table with borders and colors, use copyFormat="rich"; to include a row of column names, use copyHeaders (since 1.12.0; Formatted copy).

Cut (Ctrl/Cmd+X)

Writes the selected range to the clipboard in the same form as copy and marks it with a dotted line (since 1.10.0, on by default). The values don't change yet; only when you paste the same text into this grid are the original cells cleared, together with the paste (one change; one Ctrl/Cmd+Z restores both).

  • When you paste into another app, after the dotted line is gone (Escape, starting an edit, a change of sorting or filtering), or when an original cell's value changed in between, it becomes a normal paste and the originals stay (no data is lost).
  • Cells that aren't cleared: cells that can't be edited, cells that don't accept empty with 'reject', label rows and group rows, rows excluded by isRowExportable, and cells that overlap the paste target.
  • To turn it off, use excelShortcuts={false} (turns off the other Excel keys too) or excelShortcuts={{ cut: false }}. The other Excel keys are in "Excel keys" in Keyboard and touch.

Paste (Ctrl/Cmd+V)

<SpreadsheetGrid
  rows={rows}
  onRowsChange={setRows}
  columns={columns}
  createRow={() => ({ id: crypto.randomUUID(), name: '', qty: null })} // rows that spill past the end
/>
  • Where pasting starts: the top left of the selected range, the first data row of a selected column, or the first column of a selected row (from the active cell if it is outside the selection). Copying one cell and pasting into a range of cells writes the same value into the whole range (as in Excel. Since 1.2.0). When the range's row and column counts are multiples of the copied ones (2 copied rows into a 6-row range, for example), it repeats to fill too. Column / row selections and ranges that don't divide evenly get one paste. With serverSide, when the range includes rows not yet loaded, it also pastes once. To paste once from the top left as up to 1.1, use pasteFillsSelection={false}.
  • Skipped: cells that can't be edited (readOnly / editable: false / canEditCell), label rows and group rows (pasting continues into the next data row), synthetic columns (writing starts from the data column to their right), and cells in validationMode: 'reject' columns whose value fails validation. Cells that can't be edited and cells with invalid values are reported together once per paste through onPasteSkipped (since 1.1.0; cells[i].reason is 'readOnly' / 'invalid'). Empty text pasted into cells that can't be edited (empty cells in an Excel range) isn't counted (since 1.3.0).
  • How values are read: with the column's parseClipboardValue if any, otherwise with the default parser for the editor type (number reads full-width digits and 1,234 as numbers, date turns 2026/3/15 and the like into 'YYYY-MM-DD', checkbox treats true / 1 as checked and empty as unchecked). Clearing with Delete and committing an editor go through the same parser. Excel currency formats such as "¥12,000" and "(1,200)" can't be read by the default parser, so use parseClipboardValue: numberParser({ strip: ['¥', '円'], negativeParentheses: true }) (since 1.1.0; "Values paste can't read" in GridColumn).
  • When it spills over: rows past the end of the table are added only when there is a createRow; otherwise they are dropped. Columns past the right edge are added only when there are createOverflowColumn and onColumnsChange.
  • One paste calls onRowsChange once and is one undo (added rows go back too; added columns don't). A paste with no cell it can write doesn't call onRowsChange, adds nothing to the undo history and adds no rows / columns (since 1.3.0).
  • With the whole grid readOnly, it does nothing. Pasting inside an editor or an input you placed in a cell is that input's normal paste.
  • With serverSide, rows not loaded are skipped and no rows or columns are added. Written values are saved through dataSource.updateRows.

Changing rows from a button outside the grid

When you change rows from outside the grid, as with "Delete the selected rows", replacing them directly with setRows clears the undo history (the grid doesn't know about that change). To make it undoable, pass it through the handle's applyRows(next).

const deleteSelected = () => {
  const keys = new Set(gridRef.current?.getSelectedRowKeys() ?? []);
  gridRef.current?.applyRows(rows.filter((row) => !keys.has(row.id)));
};
  • The function form applyRows((prev) => next) works too (since 1.1.0). prev is the rows last passed, so consecutive calls stack.
  • For tables that change from outside all the time, like stock prices, use applyRows(next, { undoable: false }) to keep outside updates out of undo (since 1.1.0. The current history isn't cleared, and undo reverts only edits made in the grid; "Tables that change from outside all the time" in Cell editing).

All handle methods are in Imperative API, and the list of keys is in Keyboard and touch.

On this page