React Data Grid
react-data-grid is a high-performance, feature-rich data grid component for React applications, currently in `7.0.0-beta.59`. It is engineered for efficiency with large datasets through virtualization, rendering only visible rows and columns. The library offers extensive customization options, including frozen columns, multi-column sorting, row and column grouping, row selection, cell editing, and adaptable renderers. It ships with comprehensive TypeScript support, ensuring type safety across its API. `react-data-grid` supports React 19.2+, modern browsers, and server-side rendering, prioritizing bundle size efficiency with tree-shaking and no external runtime dependencies. The project maintains an active development pace with frequent beta releases, incorporating features like keyboard accessibility, light/dark modes, and RTL support, though a stable v7 release date is not yet scheduled.
Common errors
-
Module not found: Error: Can't resolve 'react-data-grid/lib/styles.css'
cause The default stylesheet for `react-data-grid` was not imported.fixAdd `import 'react-data-grid/lib/styles.css';` to your application's entry file or a global CSS file. -
TypeError: DataGrid is not a function (or similar `Cannot read properties of undefined (reading 'DataGrid')` when using CommonJS)
cause `react-data-grid` v7 is published as ESM, and direct `require()` calls in a CommonJS environment without proper transpilation/bundling can fail.fixEnsure your project is configured for ESM imports (e.g., using Babel or a modern bundler like Webpack/Vite that handles ESM). Use `import { DataGrid } from 'react-data-grid';` syntax. -
Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
cause This error often occurs when you have multiple versions of React installed, or if `react-data-grid` is using a different React instance than your application.fixCheck your `package.json` and `yarn.lock`/`package-lock.json` for duplicate React installations. Use `npm dedupe` or `yarn why react` to identify and resolve conflicts, ensuring only one React version is used.
Warnings
- breaking The `textEditor` prop in column definitions was renamed to `renderTextEditor` for improved clarity and consistency in `v7.0.0-beta.59`.
- gotcha When using `rolldown-vite` for CSS minification, there's a known bug with `lightningcss` (the default minifier) that affects `light-dark` syntax. This can lead to incorrect styling.
- breaking Version 7 of `react-data-grid` has a peer dependency on `React 19.2+`. Using older versions of React may lead to compatibility issues or unexpected behavior.
- breaking Several props related to filtering were removed in `v7.0.0-canary.48`, including `headerFiltersHeight`, `filters`, `onFiltersChange`, and `enableFilterRow`, along with `Column.filterRenderer` and exports like `FilterRendererProps`, `Filters`.
Install
-
npm install react-data-grid -
yarn add react-data-grid -
pnpm add react-data-grid
Imports
- DataGrid
const DataGrid = require('react-data-grid').DataGrid;import { DataGrid } from 'react-data-grid'; - Column
import { Column } from 'react-data-grid';import type { Column } from 'react-data-grid'; - styles.css
import 'react-data-grid/lib/styles.css';
Quickstart
import React from 'react';
import { DataGrid, type Column } from 'react-data-grid';
import 'react-data-grid/lib/styles.css';
interface Row {
id: number;
title: string;
status: 'todo' | 'in-progress' | 'done';
priority: 'low' | 'medium' | 'high';
}
const initialRows: Row[] = Array.from({ length: 50 }, (_, i) => ({
id: i,
title: `Task ${i + 1}`,
status: i % 3 === 0 ? 'todo' : i % 3 === 1 ? 'in-progress' : 'done',
priority: i % 4 === 0 ? 'high' : i % 4 === 1 ? 'medium' : 'low'
}));
const columns: readonly Column<Row>[] = [
{ key: 'id', name: 'ID', width: 60, resizable: true },
{ key: 'title', name: 'Title', resizable: true, sortable: true },
{ key: 'status', name: 'Status', resizable: true, sortable: true },
{ key: 'priority', name: 'Priority', resizable: true, sortable: true }
];
function MyDataGrid() {
const [rows, setRows] = React.useState(initialRows);
const onRowsChange = (updatedRows: Row[]) => {
setRows(updatedRows);
};
return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid
columns={columns}
rows={rows}
onRowsChange={onRowsChange}
rowKeyGetter={(row) => row.id}
className="rdg-grid"
/>
</div>
);
}
export default MyDataGrid;