The DataGrid component is designed to handle large datasets efficiently while offering a rich set of features for customization and interactivity.
- React 19.2+ support
- Evergreen browsers and server-side rendering support
- Tree-shaking support with no external dependencies to keep your bundles slim
- Great performance thanks to virtualization: columns and rows outside the viewport are not rendered
- Strictly typed with TypeScript
- Keyboard accessibility
- Light and dark mode support out of the box.
- Frozen columns: Freeze columns to keep them visible during horizontal scrolling.
- Column resizing
- Multi-column sorting
- Click on a sortable column header to toggle between its ascending/descending sort order
- Ctrl+Click / Meta+Click to sort an additional column
- Column spanning
- Column grouping
- Row selection
- Row grouping
- Summary rows
- Dynamic row heights
- No rows fallback
- Cell formatting
- Cell editing
- Cell copy / pasting
- Cell value dragging / filling
- Customizable Renderers
- Right-to-left (RTL) support.
Important
rolldown-viteby default useslightningcssto minify css which has a bug minifying light-dark syntax. You can switch toesbuildas a workaround
build: { ....,cssMinify: 'esbuild'}Install react-data-grid using your favorite package manager:
npm i react-data-gridpnpm add react-data-gridyarn add react-data-gridbun add react-data-gridAdditionally, import the default styles in your application:
import'react-data-grid/lib/styles.css';react-data-grid is published as ECMAScript modules for evergreen browsers, bundlers, and server-side rendering.
Here is a basic example of how to use react-data-grid in your React application:
import'react-data-grid/lib/styles.css';import{DataGrid,typeColumn}from'react-data-grid';interfaceRow{id: number;title: string;}constcolumns: readonlyColumn<Row>[]=[{key: 'id',name: 'ID'},{key: 'title',name: 'Title'}];constrows: readonlyRow[]=[{id: 0,title: 'Example'},{id: 1,title: 'Demo'}];functionApp(){return<DataGridcolumns={columns}rows={rows}/>;}Set --rdg-color-scheme: light/dark at the :root to control the color theme. The light or dark themes can be enforced using the rdg-light or rdg-dark classes.
An array of column definitions. Each column should have a key and name. See the Column type for all available options.
columns array will trigger a re-render and recalculation for the entire grid. Always memoize this prop using useMemo or define it outside the component to avoid unnecessary re-renders.
An array of rows, the rows data can be of any type.
💡 Performance: The grid is optimized for efficient rendering:
Virtualization: Only visible rows are rendered in the DOM
Individual row updates: Row components are memoized, so updating a single row object will only re-render that specific row, not all rows
Array reference matters: Changing the array reference itself (e.g.,
setRows([...rows])) triggers viewport and layout recalculations, even if the row objects are unchangedBest practice: When updating rows, create a new array but reuse unchanged row objects. For example:
// ✅ Good: Only changed row is re-renderedsetRows(rows.map((row,idx)=>(idx===targetIdx ? { ...row,updated: true} : row)));// ❌ Avoid: Creates new references for all rows, causing all visible rows to re-rendersetRows(rows.map((row)=>({ ...row})));
Rows pinned at the top of the grid for summary purposes.
Rows pinned at the bottom of the grid for summary purposes.
Function to return a unique key/identifier for each row. rowKeyGetter is required for row selection to work.
import{DataGrid}from'react-data-grid';interfaceRow{id: number;name: string;}functionrowKeyGetter(row: Row){returnrow.id;}functionMyGrid(){return<DataGridcolumns={columns}rows={rows}rowKeyGetter={rowKeyGetter}/>;}💡 While optional, setting this prop is recommended for optimal performance as the returned value is used to set the key prop on the row elements.
useCallback to prevent unnecessary re-renders.
Callback triggered when rows are changed.
The first parameter is a new rows array with both the updated rows and the other untouched rows. The second parameter is an object with an indexes array highlighting which rows have changed by their index, and the column where the change happened.
import{useState}from'react';import{DataGrid}from'react-data-grid';functionMyGrid(){const[rows,setRows]=useState(initialRows);return<DataGridcolumns={columns}rows={rows}onRowsChange={setRows}/>;}Default:35 pixels
Height of each row in pixels. A function can be used to set different row heights.
rowHeight function.
Default:35 pixels
Height of the header row in pixels.
Default:35 pixels
Height of each summary row in pixels.
A map of column widths containing both measured and resized widths. If not provided then an internal state is used.
const[columnWidths,setColumnWidths]=useState((): ColumnWidths=>newMap());functionaddNewRow(){setRows(...);// reset column widths after adding a new rowsetColumnWidths(newMap());}return<DataGridcolumnWidths={columnWidths}onColumnWidthsChange={setColumnWidths}.../>Callback triggered when column widths change. If not provided then an internal state is used.
A set of selected row keys. rowKeyGetter is required for row selection to work.
Function to determine if row selection is disabled for a specific row.
Callback triggered when the selection changes.
import{useState}from'react';import{DataGrid,SelectColumn}from'react-data-grid';constrows: readonlyRows[]=[...];constcolumns: readonlyColumn<Row>[]=[SelectColumn,// other columns];functionrowKeyGetter(row: Row){returnrow.id;}functionisRowSelectionDisabled(row: Row){return!row.isActive;}functionMyGrid(){const[selectedRows,setSelectedRows]=useState((): ReadonlySet<number>=>newSet());return(<DataGridrowKeyGetter={rowKeyGetter}columns={columns}rows={rows}selectedRows={selectedRows}isRowSelectionDisabled={isRowSelectionDisabled}onSelectedRowsChange={setSelectedRows}/>);}An array of sorted columns.
Callback triggered when sorting changes.
import{useState}from'react';import{DataGrid,SelectColumn}from'react-data-grid';constrows: readonlyRows[]=[...];constcolumns: readonlyColumn<Row>[]=[{key: 'name',name: 'Name',sortable: true},// other columns];functionMyGrid(){const[sortColumns,setSortColumns]=useState<readonlySortColumn[]>([]);return(<DataGridcolumns={columns}rows={rows}sortColumns={sortColumns}onSortColumnsChange={setSortColumns}/>);}More than one column can be sorted via ctrl (command) + click. To disable multiple column sorting, change the onSortColumnsChange function to
functiononSortColumnsChange(sortColumns: SortColumn[]){setSortColumns(sortColumns.slice(-1));}Default options applied to all columns.
functionMyGrid(){return(<DataGridcolumns={columns}rows={rows}defaultColumnOptions={{minWidth: 100,resizable: true,sortable: true,draggable: true}}/>);}Callback triggered when a pointer becomes active in a cell. The default behavior is to select the cell. Call preventGridDefault to prevent the default behavior.
functiononCellMouseDown(args: CellMouseDownArgs<R,SR>,event: CellMouseEvent){if(args.column.key==='id'){event.preventGridDefault();}}<DataGridrows={rows}columns={columns}onCellMouseDown={onCellMouseDown}/>;Callback triggered when a cell is clicked.
functiononCellClick(args: CellMouseArgs<R,SR>,event: CellMouseEvent){if(args.column.key==='id'){event.preventGridDefault();}}<DataGridrows={rows}columns={columns}onCellClick={onCellClick}/>;This event can be used to open cell editor on single click
functiononCellClick(args: CellMouseArgs<R,SR>,event: CellMouseEvent){if(args.column.key==='id'){args.selectCell(true);}}Callback triggered when a cell is double-clicked. The default behavior is to open the editor if the cell is editable. Call preventGridDefault to prevent the default behavior.
functiononCellDoubleClick(args: CellMouseArgs<R,SR>,event: CellMouseEvent){if(args.column.key==='id'){event.preventGridDefault();}}<DataGridrows={rows}columns={columns}onCellDoubleClick={onCellDoubleClick}/>;Callback triggered when a cell is right-clicked.
functiononCellContextMenu(args: CellMouseArgs<R,SR>,event: CellMouseEvent){if(args.column.key==='id'){event.preventDefault();// open custom context menu}}<DataGridrows={rows}columns={columns}onCellContextMenu={onCellContextMenu}/>;A function called when keydown event is triggered on a cell. This event can be used to customize cell navigation and editing behavior.
Examples
- Prevent editing on
Enter
functiononCellKeyDown(args: CellKeyDownArgs<R,SR>,event: CellKeyboardEvent){if(args.mode==='SELECT'&&event.key==='Enter'){event.preventGridDefault();}}- Prevent navigation on
Tab
functiononCellKeyDown(args: CellKeyDownArgs<R,SR>,event: CellKeyboardEvent){if(args.mode==='SELECT'&&event.key==='Tab'){event.preventGridDefault();}}Check more examples
onCellCopy?: Maybe<(args: CellCopyArgs<NoInfer<R>, NoInfer<SR>>, event: CellClipboardEvent) => void>
Callback triggered when a cell's content is copied.
onCellPaste?: Maybe<(args: CellPasteArgs<NoInfer<R>, NoInfer<SR>>, event: CellClipboardEvent) => void>
Callback triggered when content is pasted into a cell.
Triggered when the selected cell is changed.
Arguments:
args.rowIdx:number- row indexargs.row:R- row object of the currently selected cellargs.column:CalculatedColumn<TRow, TSummaryRow>- column object of the currently selected cell
Callback triggered when the grid is scrolled.
Callback triggered when column is resized.
Callback triggered when columns are reordered.
Default:true
This prop can be used to disable virtualization.
Custom renderers for cells, rows, and other components.
interfaceRenderers<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>;}For example, the default <Row /> component can be wrapped via the renderRow prop to add contexts or tweak props
import{DataGrid,RenderRowProps,Row}from'react-data-grid';functionmyRowRenderer(key: React.Key,props: RenderRowProps<Row>){return(<MyContextkey={key}value={123}><Row{...props}/></MyContext>);}functionMyGrid(){return<DataGridcolumns={columns}rows={rows}renderers={{renderRow: myRowRenderer}}/>;}Function to apply custom class names to rows.
import{DataGrid}from'react-data-grid';functionMyGrid(){return<DataGridcolumns={columns}rows={rows}rowClass={rowClass}/>;}functionrowClass(row: Row,rowIdx: number){returnrowIdx%2===0 ? 'even' : 'odd';}useCallback to avoid re-rendering all rows on every render.
Custom class name for the header row.
This property sets the text direction of the grid, it defaults to 'ltr' (left-to-right). Setting direction to 'rtl' has the following effects:
- Columns flow from right to left
- Frozen columns are pinned on the right
- Column resize cursor is shown on the left edge of the column
- Scrollbar is moved to the left
Custom class name for the grid.
Custom styles for the grid.
The label of the grid. We recommend providing a label using aria-label or aria-labelledby
The id of the element containing a label for the grid. We recommend providing a label using aria-label or aria-labelledby
If the grid has a caption or description, aria-describedby can be set on the grid element with a value referring to the element containing the description.
This prop can be used to add a testid for testing. We recommend querying the grid by by its role and name.
functionMyGrid(){return<DataGridaria-label="my-grid"columns={columns}rows={rows}/>;}test('grid',async()=>{awaitrender(<MyGrid/>);constgrid=screen.getByRole('grid',{name: 'my-grid'});});TreeDataGrid is a component built on top of DataGrid to add hierarchical row grouping. This implements the Treegrid pattern.
How it works:
- The
groupByprop specifies which columns should be used for grouping - The
rowGrouperfunction groups rows by the specified column keys - Group rows are rendered with expand/collapse toggles
- Child rows are nested under their parent groups
- Groups can be expanded/collapsed by clicking the toggle or using keyboard navigation (←, →)
Keyboard Navigation:
- → (Right Arrow): Expand a collapsed group row when focused
- ← (Left Arrow): Collapse an expanded group row when focused, or navigate to parent group
Unsupported Props:
The following DataGrid props are not supported in TreeDataGrid:
onFill- Drag-fill is disabled for tree gridsisRowSelectionDisabled- Row selection disabling is not available
Caveats:
- Group columns cannot be rendered under one column
- Group columns are automatically frozen and cannot be unfrozen
- Cell copy/paste does not work on group rows
All DataGridProps are supported except those listed above, plus the following additional props:
Required. An array of column keys to group by. The order determines the grouping hierarchy (first key is the top level, second key is nested under the first, etc.).
import{TreeDataGrid,typeColumn}from'react-data-grid';interfaceRow{id: number;country: string;city: string;name: string;}constcolumns: readonlyColumn<Row>[]=[{key: 'country',name: 'Country'},{key: 'city',name: 'City'},{key: 'name',name: 'Name'}];functionMyGrid(){return(<TreeDataGridcolumns={columns}rows={rows}groupBy={['country','city']}// ... other props/>);}Required. A function that groups rows by the specified column key. Returns an object where keys are the group values and values are arrays of rows belonging to that group.
functionrowGrouper(rows: Row[],columnKey: string){returnObject.groupBy(rows,(row)=>row[columnKey]);}Required. A set of group IDs that are currently expanded. Group IDs are generated by groupIdGetter.
import{useState}from'react';import{TreeDataGrid}from'react-data-grid';functionMyGrid(){const[expandedGroupIds,setExpandedGroupIds]=useState((): ReadonlySet<unknown>=>newSet());return(<TreeDataGridexpandedGroupIds={expandedGroupIds}onExpandedGroupIdsChange={setExpandedGroupIds}// ... other props/>);}Required. Callback triggered when groups are expanded or collapsed.
Function to generate unique IDs for group rows. If not provided, a default implementation is used that concatenates parent and group keys with __.
Note: Unlike DataGrid, the rowHeight function receives RowHeightArgs<R> which includes a type property to distinguish between regular rows and group rows:
functiongetRowHeight(args: RowHeightArgs<Row>): number{if(args.type==='GROUP'){return50;// Custom height for group rows}return35;// Height for regular rows}<TreeDataGridrowHeight={getRowHeight}.../>The default row component. Can be wrapped via the renderers.renderRow prop.
RenderRowProps<TRow, TSummaryRow>
The default cell component. Can be wrapped via the renderers.renderCell prop.
CellRendererProps<TRow, TSummaryRow>
A formatter component for rendering row selection checkboxes.
Whether the checkbox is checked.
The tab index for keyboard navigation.
Whether the checkbox is disabled.
Callback when the checkbox state changes.
Optional click handler.
Accessible label for the checkbox.
ID of the element that labels the checkbox.
Hook for managing header row selection state. Used within custom header cell renderers to implement custom "select all" functionality.
Returns:
isIndeterminate: boolean- Whether some (but not all) rows are selectedisRowSelected: boolean- Whether all rows are selectedonRowSelectionChange: (event: SelectHeaderRowEvent) => void- Callback to change selection state
Example:
functionCustomHeaderCell(){const{ isIndeterminate, isRowSelected, onRowSelectionChange }=useHeaderRowSelection();return(<inputtype="checkbox"checked={isRowSelected}indeterminate={isIndeterminate}onChange={(event)=>onRowSelectionChange({checked: event.target.checked})}/>);}Hook for managing row selection state. Used within custom cell renderers to implement custom row selection.
Returns:
isRowSelectionDisabled: boolean- Whether selection is disabled for this rowisRowSelected: boolean- Whether this row is selectedonRowSelectionChange: (event: SelectRowEvent<R>) => void- Callback to change selection state
Example:
functionCustomSelectCell({ row }: RenderCellProps<Row>){const{ isRowSelectionDisabled, isRowSelected, onRowSelectionChange }=useRowSelection();return(<inputtype="checkbox"disabled={isRowSelectionDisabled}checked={isRowSelected}onChange={(event)=>onRowSelectionChange({ row,checked: event.target.checked,isShiftClick: event.nativeEvent.shiftKey})}/>);}The default header cell renderer. Renders sortable columns with sort indicators.
Example:
import{renderHeaderCell,typeColumn}from'react-data-grid';constcolumns: readonlyColumn<Row>[]=[{key: 'name',name: 'Name',sortable: true, renderHeaderCell }];A basic text editor provided for convenience.
Example:
import{renderTextEditor,typeColumn}from'react-data-grid';constcolumns: readonlyColumn<Row>[]=[{key: 'title',name: 'Title',renderEditCell: renderTextEditor}];Renders the sort direction arrow icon.
Props:
sortDirection: SortDirection | undefined- 'ASC', 'DESC', or undefined
Renders the sort priority number for multi-column sorting.
Props:
priority: number | undefined- The sort priority (1, 2, 3, etc.)
Renders a checkbox input with proper styling and accessibility.
Props:
checked: boolean- Whether the checkbox is checkedindeterminate?: boolean- Whether the checkbox is in indeterminate statedisabled?: boolean- Whether the checkbox is disabledonChange: (checked: boolean, shift: boolean) => void- Change handlertabIndex: number- Tab index for keyboard navigationaria-label?: string- Accessible labelaria-labelledby?: string- ID of labeling element
Example:
import{DataGrid,renderCheckbox}from'react-data-grid';<DataGridrenderers={{renderCheckbox: (props)=>renderCheckbox({ ...props,'aria-label': 'Select row'})}}/>;The default group cell renderer used by the columns used for grouping (groupBy prop). This renders the expand/collapse toggle.
RenderGroupCellProps<TRow, TSummaryRow>
Example:
import{renderToggleGroup,typeColumn}from'react-data-grid';constcolumns: readonlyColumn<Row>[]=[{key: 'group',name: 'Group',renderGroupCell: renderToggleGroup}];The default cell renderer that renders the value of row[column.key].
Example:
import{renderValue,typeColumn}from'react-data-grid';constcolumns: readonlyColumn<Row>[]=[{key: 'title',name: 'Title',renderCell: renderValue}];Context for providing default renderers to DataGrids in your app.
Example:
import{DataGridDefaultRenderersContext,typeRenderers}from'react-data-grid';// custom implementations of renderersconstdefaultGridRenderers: Renderers<unknown,unknown>={ renderCheckbox, renderSortStatus };functionAppProvider({ children }){return(<DataGridDefaultRenderersContextvalue={defaultGridRenderers}>{children}</DataGridDefaultRenderersContext>);}A pre-configured column for row selection. Includes checkbox renderers for header, regular rows, and grouped rows.
Example:
import{DataGrid,SelectColumn,typeColumn}from'react-data-grid';constcolumns: readonlyColumn<Row>[]=[SelectColumn, ...otherColumns];functionrowKeyGetter(row: Row){returnrow.id;}functionMyGrid(){return(<DataGridcolumns={columns}rows={rows}rowKeyGetter={rowKeyGetter}selectedRows={selectedRows}onSelectedRowsChange={setSelectedRows}/>);}The key used for the SelectColumn. Useful for identifying or filtering the select column.
Example:
import{SELECT_COLUMN_KEY}from'react-data-grid';constnonSelectColumns=columns.filter((column)=>column.key!==SELECT_COLUMN_KEY);Defines the configuration for a column in the grid.
The name of the column. Displayed in the header cell by default.
A unique key to distinguish each column
Defaultauto
Width can be any valid css grid column value. If not specified, it will be determined automatically based on grid width and specified widths of other columns.
width: 80,// pixelswidth: '25%',width: 'max-content',width: 'minmax(100px, max-content)',max-content can be used to expand the column to show all the content. Note that the grid is only able to calculate column width for visible rows.
Default: 50 pixels
Minimum column width in pixels.
Maximum column width in pixels.
Class name(s) for cells. Can be a string or a function that returns a class name based on the row.
Class name(s) for the header cell.
Class name(s) for summary cells. Can be a string or a function that returns a class name based on the summary row.
Render function to render the content of cells.
Render function to render the content of the header cell.
Render function to render the content of summary cells
Render function to render the content of group cells when using TreeDataGrid.
Render function to render the content of edit cells. When set, the column is automatically set to be editable
Control whether cells can be edited with renderEditCell.
Function to determine how many columns this cell should span. Returns the number of columns to span, or undefined for no spanning. See the ColSpanArgs type in the Types section below.
Example:
importtype{Column}from'react-data-grid';constcolumns: readonlyColumn<Row>[]=[{key: 'title',name: 'Title',colSpan(args){if(args.type==='ROW'&&args.row.isFullWidth){return5;// Span 5 columns for full-width rows}returnundefined;}}];Default: false
Determines whether column is frozen. Frozen columns are pinned on the left. At the moment we do not support pinning columns on the right.
Default: false
Enable resizing of the column
Default: false
Enable sorting of the column
Default: false
Enable dragging of the column
Default: false
Sets the column sort order to be descending instead of ascending the first time the column is sorted
Options for cell editing.
Default: false
Render the cell content in addition to the edit cell content. Enable this option when the editor is rendered outside the grid, like a modal for example.
Default: true
Commit changes when clicking outside the cell.
Default: true
Close the editor when the row value changes externally.
Defines a group of columns that share a common header.
interfaceColumnGroup<R,SR=unknown>{readonlyname: string|ReactElement;readonlyheaderCellClass?: Maybe<string>;readonlychildren: readonlyColumnOrColumnGroup<R,SR>[];}Example:
importtype{ColumnOrColumnGroup}from'react-data-grid';constcolumns: readonlyColumnOrColumnGroup<Row>[]=[{name: 'Personal Info',children: [{key: 'firstName',name: 'First Name'},{key: 'lastName',name: 'Last Name'}]}];Union type representing either a Column or a ColumnGroup.
Extends Column with additional computed properties used internally by the grid. This is the type passed to render functions.
Additional properties:
idx: number- The column indexlevel: number- Nesting level when using column groupsparent: CalculatedColumnParent | undefined- Parent column group if nested- Multiple Column properties have their values set to their default value
Represents a parent column group in the calculated column structure.
interfaceCalculatedColumnParent<R,SR>{readonlyname: string|ReactElement;readonlyparent: CalculatedColumnParent<R,SR>|undefined;readonlyidx: number;readonlycolSpan: number;readonlylevel: number;readonlyheaderCellClass?: Maybe<string>;}Union type representing either a CalculatedColumnParent or a CalculatedColumn.
typeCalculatedColumnOrColumnGroup<R,SR>=CalculatedColumnParent<R,SR>|CalculatedColumn<R,SR>;Arguments passed to the rowHeight function when it's a function.
typeRowHeightArgs<TRow>={type: 'ROW';row: TRow}|{type: 'GROUP';row: GroupRow<TRow>};Example:
functiongetRowHeight(args: RowHeightArgs<Row>): number{if(args.type==='GROUP'){return40;}returnargs.row.isLarge ? 60 : 35;}<DataGridrowHeight={getRowHeight}.../>Props passed to custom cell renderers.
interfaceRenderCellProps<TRow,TSummaryRow=unknown>{column: CalculatedColumn<TRow,TSummaryRow>;row: TRow;rowIdx: number;isCellEditable: boolean;tabIndex: number;onRowChange: (row: TRow)=>void;}Example:
importtype{RenderCellProps}from'react-data-grid';functionrenderCell({ row, column, onRowChange }: RenderCellProps<MyRow>){return(<div>{row[column.key]}<buttononClick={()=>onRowChange({ ...row,updated: true})}>Update</button></div>);}Props passed to custom header cell renderers.
interfaceRenderHeaderCellProps<TRow,TSummaryRow=unknown>{column: CalculatedColumn<TRow,TSummaryRow>;sortDirection: SortDirection|undefined;priority: number|undefined;tabIndex: number;}Props passed to custom edit cell renderers (editors).
interfaceRenderEditCellProps<TRow,TSummaryRow=unknown>{column: CalculatedColumn<TRow,TSummaryRow>;row: TRow;rowIdx: number;onRowChange: (row: TRow,commitChanges?: boolean)=>void;onClose: (commitChanges?: boolean,shouldFocusCell?: boolean)=>void;}Example:
importtype{RenderEditCellProps}from'react-data-grid';functionCustomEditor({ row, column, onRowChange, onClose }: RenderEditCellProps<MyRow>){return(<inputautoFocusvalue={row[column.key]}onChange={(event)=>onRowChange({ ...row,[column.key]: event.target.value})}onBlur={()=>onClose(true)}/>);}Props passed to summary cell renderers.
interfaceRenderSummaryCellProps<TSummaryRow,TRow=unknown>{column: CalculatedColumn<TRow,TSummaryRow>;row: TSummaryRow;tabIndex: number;}Props passed to group cell renderers when using TreeDataGrid.
interfaceRenderGroupCellProps<TRow,TSummaryRow=unknown>{groupKey: unknown;column: CalculatedColumn<TRow,TSummaryRow>;row: GroupRow<TRow>;childRows: readonlyTRow[];isExpanded: boolean;tabIndex: number;toggleGroup: ()=>void;}Props passed to custom row renderers.
interfaceRenderRowProps<TRow,TSummaryRow=unknown>{row: TRow;viewportColumns: readonlyCalculatedColumn<TRow,TSummaryRow>[];rowIdx: number;selectedCellIdx: number|undefined;isRowSelected: boolean;isRowSelectionDisabled: boolean;gridRowStart: number;lastFrozenColumnIndex: number;draggedOverCellIdx: number|undefined;selectedCellEditor: ReactElement<RenderEditCellProps<TRow>>|undefined;onRowChange: (column: CalculatedColumn<TRow,TSummaryRow>,rowIdx: number,newRow: TRow)=>void;rowClass: Maybe<(row: TRow,rowIdx: number)=>Maybe<string>>;// ... and event handlers}Props passed to the cell renderer when using renderers.renderCell.
Extends RenderRowProps with cell-specific properties like column, colSpan, isCellSelected, etc.
Custom renderer configuration for the grid.
interfaceRenderers<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>;}Arguments passed to cell mouse event handlers.
interfaceCellMouseArgs<TRow,TSummaryRow=unknown>{column: CalculatedColumn<TRow,TSummaryRow>;row: TRow;rowIdx: number;selectCell: (enableEditor?: boolean)=>void;}The column object of the cell.
The row object of the cell.
The row index of the cell.
Function to manually select the cell. Pass true to immediately start editing.
Example:
importtype{CellMouseArgs,CellMouseEvent}from'react-data-grid';functiononCellClick(args: CellMouseArgs<Row>,event: CellMouseEvent){console.log('Clicked cell at row',args.rowIdx,'column',args.column.key);args.selectCell(true);// Select and start editing}Extends React.MouseEvent<HTMLDivElement> with grid-specific methods.
Prevents the default grid behavior for this event.
Returns whether preventGridDefault was called.
Example:
importtype{CellMouseArgs,CellMouseEvent}from'react-data-grid';functiononCellClick(args: CellMouseArgs<Row>,event: CellMouseEvent){if(args.column.key==='actions'){event.preventGridDefault();// Prevent cell selection}}Extends React.KeyboardEvent<HTMLDivElement> with grid-specific methods.
Prevents the default grid behavior for this keyboard event.
Returns whether preventGridDefault was called.
Type alias for React.ClipboardEvent<HTMLDivElement>. Used for copy and paste events.
typeCellClipboardEvent=React.ClipboardEvent<HTMLDivElement>;Arguments passed to the onCellKeyDown handler. The shape differs based on whether the cell is in SELECT or EDIT mode.
SELECT mode:
interfaceSelectCellKeyDownArgs<TRow,TSummaryRow>{mode: 'SELECT';column: CalculatedColumn<TRow,TSummaryRow>;row: TRow;rowIdx: number;selectCell: (position: Position,options?: SelectCellOptions)=>void;}EDIT mode:
interfaceEditCellKeyDownArgs<TRow,TSummaryRow>{mode: 'EDIT';column: CalculatedColumn<TRow,TSummaryRow>;row: TRow;rowIdx: number;navigate: ()=>void;onClose: (commitChanges?: boolean,shouldFocusCell?: boolean)=>void;}Example:
importtype{CellKeyboardEvent,CellKeyDownArgs}from'react-data-grid';functiononCellKeyDown(args: CellKeyDownArgs<Row>,event: CellKeyboardEvent){if(args.mode==='EDIT'&&event.key==='Escape'){args.onClose(false);// Close without committingevent.preventGridDefault();}}Arguments passed to onSelectedCellChange.
interfaceCellSelectArgs<TRow,TSummaryRow=unknown>{rowIdx: number;row: TRow|undefined;column: CalculatedColumn<TRow,TSummaryRow>;}Arguments passed to onCellCopy.
interfaceCellCopyArgs<TRow,TSummaryRow=unknown>{column: CalculatedColumn<TRow,TSummaryRow>;row: TRow;}Arguments passed to onCellPaste.
interfaceCellPasteArgs<TRow,TSummaryRow=unknown>{column: CalculatedColumn<TRow,TSummaryRow>;row: TRow;}Arguments passed to the colSpan function.
typeColSpanArgs<TRow,TSummaryRow>=|{type: 'HEADER'}|{type: 'ROW';row: TRow}|{type: 'SUMMARY';row: TSummaryRow};Example:
importtype{Column}from'react-data-grid';constcolumns: readonlyColumn<Row>[]=[{key: 'title',name: 'Title',colSpan(args){if(args.type==='ROW'&&args.row.isFullWidth){return3;// Span 3 columns}returnundefined;}}];Describes a sorted column.
interfaceSortColumn{readonlycolumnKey: string;readonlydirection: SortDirection;}typeSortDirection='ASC'|'DESC';Data provided to onRowsChange callback.
interfaceRowsChangeData<R,SR=unknown>{indexes: number[];column: CalculatedColumn<R,SR>;}indexes: Array of row indexes that changedcolumn: The column where changes occurred
Event object for row selection changes.
interfaceSelectRowEvent<TRow>{row: TRow;checked: boolean;isShiftClick: boolean;}Event object for header row selection changes.
interfaceSelectHeaderRowEvent{checked: boolean;}Event object for drag-fill operations.
interfaceFillEvent<TRow>{columnKey: string;sourceRow: TRow;targetRow: TRow;}Used with the onFill prop to handle cell value dragging.
Represents a grouped row in TreeDataGrid.
interfaceGroupRow<TRow>{readonlychildRows: readonlyTRow[];readonlyid: string;readonlyparentId: unknown;readonlygroupKey: unknown;readonlyisExpanded: boolean;readonlylevel: number;readonlyposInSet: number;readonlysetSize: number;readonlystartRowIndex: number;}A map of column widths.
typeColumnWidths=ReadonlyMap<string,ColumnWidth>;interfaceColumnWidth{readonlytype: 'resized'|'measured';readonlywidth: number;}Used with columnWidths and onColumnWidthsChange props to control column widths externally.
Represents a cell position in the grid.
interfacePosition{readonlyidx: number;// Column indexreadonlyrowIdx: number;// Row index}Options for programmatically selecting a cell.
interfaceSelectCellOptions{enableEditor?: Maybe<boolean>;shouldFocusCell?: Maybe<boolean>;}Props for custom checkbox renderers.
interfaceRenderCheckboxProps{checked: boolean;indeterminate?: boolean;disabled?: boolean;onChange: (checked: boolean,shift: boolean)=>void;tabIndex: number;'aria-label'?: string;'aria-labelledby'?: string;}Props for custom sort status renderers.
interfaceRenderSortStatusProps{sortDirection: SortDirection|undefined;priority: number|undefined;}Props for custom sort icon renderers.
interfaceRenderSortIconProps{sortDirection: SortDirection|undefined;}Props for custom sort priority renderers.
interfaceRenderSortPriorityProps{priority: number|undefined;}Handle type assigned to a grid's ref for programmatic grid control.
interfaceDataGridHandle{element: HTMLDivElement|null;scrollToCell: (position: Partial<Position>)=>void;selectCell: (position: Position,options?: SelectCellOptions)=>void;}Example:
import{useRef}from'react';import{DataGrid,DataGridHandle}from'react-data-grid';functionMyGrid(){constgridRef=useRef<DataGridHandle>(null);functionscrollToTop(){gridRef.current?.scrollToCell({rowIdx: 0});}return<DataGridref={gridRef}columns={columns}rows={rows}/>;}Default options applied to all columns.
typeDefaultColumnOptions<TRow,TSummaryRow>=Pick<Column<TRow,TSummaryRow>,'minWidth'|'maxWidth'|'resizable'|'sortable'|'draggable'>;Grid layout bidirectionality.
typeDirection='ltr'|'rtl';Utility type for optional values.
typeMaybe<T>=T|undefined|null;R,TRow: Row typeSR,TSummaryRow: Summary row typeK: Row key type