Skip to main content

CellMouseEvent

Extends React.MouseEvent<HTMLDivElement> with grid-specific methods.
type CellMouseEvent = CellEvent<React.MouseEvent<HTMLDivElement>>;

type CellEvent<E extends React.SyntheticEvent<HTMLDivElement>> = E & {
  preventGridDefault: () => void;
  isGridDefaultPrevented: () => boolean;
};

Methods

preventGridDefault
() => void
required
Prevents the default grid behavior for this event (e.g., cell selection).
isGridDefaultPrevented
() => boolean
required
Returns whether preventGridDefault was called.

Example

import type { CellMouseArgs, CellMouseEvent } from 'react-data-grid';

function onCellClick(args: CellMouseArgs<Row>, event: CellMouseEvent) {
  if (args.column.key === 'actions') {
    event.preventGridDefault(); // Prevent cell selection
  }
}

CellKeyboardEvent

Extends React.KeyboardEvent<HTMLDivElement> with grid-specific methods.
type CellKeyboardEvent = CellEvent<React.KeyboardEvent<HTMLDivElement>>;

type CellEvent<E extends React.SyntheticEvent<HTMLDivElement>> = E & {
  preventGridDefault: () => void;
  isGridDefaultPrevented: () => boolean;
};

Methods

preventGridDefault
() => void
required
Prevents the default grid behavior for this keyboard event (e.g., navigation, editing).
isGridDefaultPrevented
() => boolean
required
Returns whether preventGridDefault was called.

Example

import type { CellKeyboardEvent, CellKeyDownArgs } from 'react-data-grid';

function onCellKeyDown(args: CellKeyDownArgs<Row>, event: CellKeyboardEvent) {
  if (args.mode === 'EDIT' && event.key === 'Escape') {
    args.onClose(false); // Close without committing
    event.preventGridDefault();
  }
}

CellClipboardEvent

Type alias for clipboard events.
type CellClipboardEvent = React.ClipboardEvent<HTMLDivElement>;
Used for copy and paste events.

CellMouseArgs<TRow, TSummaryRow>

Arguments passed to cell mouse event handlers.
interface CellMouseArgs<TRow, TSummaryRow = unknown> {
  column: CalculatedColumn<TRow, TSummaryRow>;
  row: TRow;
  rowIdx: number;
  selectCell: (enableEditor?: boolean) => void;
}

Properties

column
CalculatedColumn<TRow, TSummaryRow>
required
The column object of the cell.
row
TRow
required
The row object of the cell.
rowIdx
number
required
The row index of the cell.
selectCell
(enableEditor?: boolean) => void
required
Function to manually select the cell. Pass true to immediately start editing.

Example

import type { CellMouseArgs, CellMouseEvent } from 'react-data-grid';

function onCellClick(args: CellMouseArgs<Row>, event: CellMouseEvent) {
  console.log('Clicked cell at row', args.rowIdx, 'column', args.column.key);
  args.selectCell(true); // Select and start editing
}

CellKeyDownArgs<TRow, TSummaryRow>

Arguments passed to the onCellKeyDown handler. The shape differs based on whether the cell is in SELECT or EDIT mode.
type CellKeyDownArgs<TRow, TSummaryRow = unknown> =
  | SelectCellKeyDownArgs<TRow, TSummaryRow>
  | EditCellKeyDownArgs<TRow, TSummaryRow>;

SELECT Mode

interface SelectCellKeyDownArgs<TRow, TSummaryRow = unknown> {
  mode: 'SELECT';
  column: CalculatedColumn<TRow, TSummaryRow> | undefined;
  row: TRow;
  rowIdx: number;
  selectCell: (position: Position, options?: SelectCellOptions) => void;
}
mode
'SELECT'
required
Indicates the cell is in select mode.
column
CalculatedColumn<TRow, TSummaryRow> | undefined
required
The column object of the selected cell, or undefined.
row
TRow
required
The row object.
rowIdx
number
required
The row index.
selectCell
(position: Position, options?: SelectCellOptions) => void
required
Function to select a different cell.

EDIT Mode

interface EditCellKeyDownArgs<TRow, TSummaryRow = unknown> {
  mode: 'EDIT';
  column: CalculatedColumn<TRow, TSummaryRow>;
  row: TRow;
  rowIdx: number;
  navigate: () => void;
  onClose: (commitChanges?: boolean, shouldFocusCell?: boolean) => void;
}
mode
'EDIT'
required
Indicates the cell is in edit mode.
column
CalculatedColumn<TRow, TSummaryRow>
required
The column object of the cell being edited.
row
TRow
required
The row object.
rowIdx
number
required
The row index.
navigate
() => void
required
Function to trigger navigation after editing.
onClose
(commitChanges?: boolean, shouldFocusCell?: boolean) => void
required
Callback to close the editor.

CellSelectArgs<TRow, TSummaryRow>

Arguments passed to onSelectedCellChange.
interface CellSelectArgs<TRow, TSummaryRow = unknown> {
  rowIdx: number;
  row: TRow | undefined;
  column: CalculatedColumn<TRow, TSummaryRow>;
}

Properties

rowIdx
number
required
The row index of the selected cell.
row
TRow | undefined
required
The row object of the selected cell, or undefined.
column
CalculatedColumn<TRow, TSummaryRow>
required
The column object of the selected cell.

CellCopyArgs<TRow, TSummaryRow>

Arguments passed to onCellCopy.
interface CellCopyArgs<TRow, TSummaryRow = unknown> {
  column: CalculatedColumn<TRow, TSummaryRow>;
  row: TRow;
}

Properties

column
CalculatedColumn<TRow, TSummaryRow>
required
The column object of the cell being copied.
row
TRow
required
The row object of the cell being copied.

CellPasteArgs<TRow, TSummaryRow>

Arguments passed to onCellPaste.
interface CellPasteArgs<TRow, TSummaryRow = unknown> {
  column: CalculatedColumn<TRow, TSummaryRow>;
  row: TRow;
}

Properties

column
CalculatedColumn<TRow, TSummaryRow>
required
The column object of the cell being pasted into.
row
TRow
required
The row object of the cell being pasted into.

SelectRowEvent<TRow>

Event object for row selection changes.
interface SelectRowEvent<TRow> {
  row: TRow;
  checked: boolean;
  isShiftClick: boolean;
}

Properties

row
TRow
required
The row being selected/deselected.
checked
boolean
required
Whether the row is being selected (true) or deselected (false).
isShiftClick
boolean
required
Whether the shift key was pressed during selection.

SelectHeaderRowEvent

Event object for header row selection changes (select all).
interface SelectHeaderRowEvent {
  checked: boolean;
}

Properties

checked
boolean
required
Whether all rows are being selected (true) or deselected (false).

FillEvent<TRow>

Event object for drag-fill operations.
interface FillEvent<TRow> {
  columnKey: string;
  sourceRow: TRow;
  targetRow: TRow;
}

Properties

columnKey
string
required
The key of the column being filled.
sourceRow
TRow
required
The source row being copied from.
targetRow
TRow
required
The target row being filled.
Used with the onFill prop to handle cell value dragging.

Position

Represents a cell position in the grid.
interface Position {
  readonly idx: number;
  readonly rowIdx: number;
}

Properties

idx
number
required
The column index.
rowIdx
number
required
The row index.

SelectCellOptions

Options for programmatically selecting a cell.
interface SelectCellOptions {
  enableEditor?: Maybe<boolean>;
  shouldFocusCell?: Maybe<boolean>;
}

Properties

enableEditor
boolean
Whether to enable the editor when selecting the cell.
shouldFocusCell
boolean
Whether to focus the cell after selection.

Build docs developers (and LLMs) love