Skip to main content

SortColumn

Describes a sorted column.
interface SortColumn {
  readonly columnKey: string;
  readonly direction: SortDirection;
}

Properties

columnKey
string
required
The key of the column being sorted.
direction
SortDirection
required
The sort direction (‘ASC’ or ‘DESC’).

SortDirection

Sort direction values.
type SortDirection = 'ASC' | 'DESC';
  • 'ASC' - Ascending order
  • 'DESC' - Descending order

RowsChangeData<TRow, TSummaryRow>

Data provided to onRowsChange callback.
interface RowsChangeData<R, SR = unknown> {
  indexes: number[];
  column: CalculatedColumn<R, SR>;
}

Properties

indexes
number[]
required
Array of row indexes that changed.
column
CalculatedColumn<R, SR>
required
The column where changes occurred.

ColSpanArgs<TRow, TSummaryRow>

Arguments passed to the colSpan function.
type ColSpanArgs<TRow, TSummaryRow> =
  | { type: 'HEADER' }
  | { type: 'ROW'; row: TRow }
  | { type: 'SUMMARY'; row: TSummaryRow };

Variants

type
'HEADER'
required
For header cells.
type
'ROW'
required
For regular row cells.
row
TRow
required
The row object.
type
'SUMMARY'
required
For summary row cells.
row
TSummaryRow
required
The summary row object.

Example

import type { Column } from 'react-data-grid';

const columns: readonly Column<Row>[] = [
  {
    key: 'title',
    name: 'Title',
    colSpan(args) {
      if (args.type === 'ROW' && args.row.isFullWidth) {
        return 3; // Span 3 columns
      }
      return undefined;
    }
  }
];

RowHeightArgs<TRow>

Arguments passed to TreeDataGrid’s rowHeight prop when it is a function.
type RowHeightArgs<TRow> =
  | { type: 'ROW'; row: TRow }
  | { type: 'GROUP'; row: GroupRow<TRow> };

Variants

type
'ROW'
required
For regular rows.
row
TRow
required
The row object.
type
'GROUP'
required
For group rows.
row
GroupRow<TRow>
required
The group row object.

Example

function getRowHeight(args: RowHeightArgs<Row>): number {
  if (args.type === 'GROUP') {
    return 40;
  }
  return args.row.isLarge ? 60 : 35;
}

<TreeDataGrid rowHeight={getRowHeight} ... />

GroupRow<TRow>

Represents a grouped row in TreeDataGrid.
interface GroupRow<TRow> {
  readonly childRows: readonly TRow[];
  readonly id: string;
  readonly parentId: unknown;
  readonly groupKey: unknown;
  readonly isExpanded: boolean;
  readonly level: number;
  readonly posInSet: number;
  readonly setSize: number;
  readonly startRowIndex: number;
}

Properties

childRows
readonly TRow[]
required
Array of child rows in this group.
id
string
required
Unique identifier for the group.
parentId
unknown
required
ID of the parent group, if nested.
groupKey
unknown
required
The group key value.
isExpanded
boolean
required
Whether the group is expanded.
level
number
required
Nesting level of the group (0 for top-level).
posInSet
number
required
Position in the set (for ARIA).
setSize
number
required
Size of the set (for ARIA).
startRowIndex
number
required
Starting row index of the group.

ColumnWidths

A map of column widths.
type ColumnWidths = ReadonlyMap<string, ColumnWidth>;

interface ColumnWidth {
  readonly type: 'resized' | 'measured';
  readonly width: number;
}

ColumnWidth Properties

type
'resized' | 'measured'
required
The type of width:
  • 'resized' - Width set by user resizing
  • 'measured' - Width measured from content
width
number
required
The width in pixels.
Used with columnWidths and onColumnWidthsChange props to control column widths externally.

Renderers<TRow, TSummaryRow>

Custom renderer configuration for the grid.
interface Renderers<TRow, TSummaryRow> {
  renderCell?: Maybe<(key: Key, props: CellRendererProps<TRow, TSummaryRow>) => ReactNode>;
  renderCheckbox?: Maybe<(props: RenderCheckboxProps) => ReactNode>;
  renderRow?: Maybe<(key: Key, props: RenderRowProps<TRow, TSummaryRow>) => ReactNode>;
  renderSortStatus?: Maybe<(props: RenderSortStatusProps) => ReactNode>;
  noRowsFallback?: Maybe<ReactNode>;
}

Properties

renderCell
(key: Key, props: CellRendererProps<TRow, TSummaryRow>) => ReactNode
Custom cell render function.
renderCheckbox
(props: RenderCheckboxProps) => ReactNode
Custom checkbox render function.
renderRow
(key: Key, props: RenderRowProps<TRow, TSummaryRow>) => ReactNode
Custom row render function.
renderSortStatus
(props: RenderSortStatusProps) => ReactNode
Custom sort status indicator render function.
noRowsFallback
ReactNode
Custom empty state to display when there are no rows.

Direction

Grid layout bidirectionality.
type Direction = 'ltr' | 'rtl';
  • 'ltr' - Left-to-right (default)
  • 'rtl' - Right-to-left

CellNavigationMode

Cell navigation mode values.
type CellNavigationMode = 'NONE' | 'CHANGE_ROW';
  • 'NONE' - No navigation when reaching the edge of a row
  • 'CHANGE_ROW' - Navigate to the next/previous row when reaching the edge

DataGridHandle

Handle type assigned to a grid’s ref for programmatic grid control.
interface DataGridHandle {
  element: HTMLDivElement | null;
  scrollToCell: (position: Partial<Position>) => void;
  selectCell: (position: Position, options?: SelectCellOptions) => void;
}

Properties

element
HTMLDivElement | null
required
Reference to the grid DOM element.
scrollToCell
(position: Partial<Position>) => void
required
Scrolls the grid to bring the specified cell into view.
gridRef.current?.scrollToCell({ rowIdx: 10, idx: 2 });
selectCell
(position: Position, options?: SelectCellOptions) => void
required
Selects the specified cell programmatically.
gridRef.current?.selectCell(
  { rowIdx: 5, idx: 1 },
  { enableEditor: true }
);

Example

import { useRef } from 'react';
import { DataGrid, DataGridHandle } from 'react-data-grid';

function MyGrid() {
  const gridRef = useRef<DataGridHandle>(null);

  function scrollToTop() {
    gridRef.current?.scrollToCell({ rowIdx: 0 });
  }

  return <DataGrid ref={gridRef} columns={columns} rows={rows} />;
}

DefaultColumnOptions<TRow, TSummaryRow>

Default options applied to all columns.
type DefaultColumnOptions<TRow, TSummaryRow> = Pick<
  Column<TRow, TSummaryRow>,
  | 'renderCell'
  | 'renderHeaderCell'
  | 'width'
  | 'minWidth'
  | 'maxWidth'
  | 'resizable'
  | 'sortable'
  | 'draggable'
>;
A subset of Column properties that can be applied as defaults to all columns.

ResizedWidth

Type for resized column width values.
type ResizedWidth = number | 'max-content';
  • number - Width in pixels
  • 'max-content' - Automatically size to content

Omit<T, K>

Utility type for omitting properties from a type.
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

Maybe<T>

Utility type for optional values.
type Maybe<T> = T | undefined | null;
Used throughout the library for nullable column/render props.

StateSetter<S>

Utility type for React state setters.
type StateSetter<S> = React.Dispatch<React.SetStateAction<S>>;

Build docs developers (and LLMs) love