Description
Excel-like grid component built with React, with editors, keyboard navigation, copy & paste, and the like http://adazzle.github.io/react-data-grid/
React Data Grid alternatives and similar libraries
Based on the "Spreadsheet" category.
Alternatively, view React Data Grid alternatives based on common mentions on social networks and blogs.
-
SheetJS js-xlsx
📗 SheetJS Spreadsheet Data Toolkit -- New home https://git.sheetjs.com/SheetJS/sheetjs -
HANDSONTABLE
JavaScript data grid with a spreadsheet look & feel. Works with React, Angular, and Vue. Supported by the Handsontable team âš¡ -
Luckysheet
DISCONTINUED. Luckysheet is an online spreadsheet like excel that is powerful, simple to configure, and completely open source. -
ag-Grid
The best JavaScript Data Table for building Enterprise Applications. Supports React / Angular / Vue / Plain JavaScript. -
jexcel
Jspreadsheet is a lightweight vanilla javascript plugin to create amazing web-based interactive tables and spreadsheets compatible with other spreadsheet software. -
MUI X
MUI X is a collection of advanced React UI components for complex use cases. Use the native integration with Material UI or extend your design system. They feature state-of-the-art functionality and complex UX workflows for data-rich applications and support a wide range of use cases. MUI X is open core—base components are MIT-licensed, while more advanced features require a Pro or Premium commercial license. Components: - Data Grid - Date and Time Pickers - Charts - Tree View
CodeRabbit: AI Code Reviews for Developers
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of React Data Grid or a related project?
README
react-data-grid
Features
- [React 18.0+](package.json) support
- [Evergreen browsers and server-side rendering](browserslist) support
- Tree-shaking support and only [one npm dependency](package.json) 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](<(https://adazzle.github.io/react-data-grid/#/common-features)>)
- Light and dark mode support out of the box. The light or dark themes can be enforced using the
rdg-light
orrdg-dark
classes. - Frozen columns
- 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
- Row selection
- Row grouping
- Summary rows
- Dynamic row heights
- No rows fallback
- Cell formatting
- Cell editing
- Cell copy / pasting
- Cell value dragging / filling
- Customizable Components
- Right-to-left (RTL) support. We recommend using Firefox as Chrome has a bug with frozen columns, and the
:dir
pseudo class is not supported
Links
- Examples website
- [Source code](website)
- Old website for react-data-grid v6
- [Changelog](CHANGELOG.md)
- [Contributing](CONTRIBUTING.md)
Install
npm install react-data-grid
react-data-grid
is published as ECMAScript modules for evergreen browsers / bundlers, and CommonJS for server-side rendering / Jest.
Quick start
import 'react-data-grid/lib/styles.css';
import DataGrid from 'react-data-grid';
const columns = [
{ key: 'id', name: 'ID' },
{ key: 'title', name: 'Title' }
];
const rows = [
{ id: 0, title: 'Example' },
{ id: 1, title: 'Demo' }
];
function App() {
return <DataGrid columns={columns} rows={rows} />;
}
API
Components
<DataGrid />
Props
columns: readonly Column<R, SR>[]
See Column
.
An array describing the grid's columns.
:warning: Passing a new columns
array will trigger a re-render for the whole grid, avoid changing it as much as possible for optimal performance.
rows: readonly R[]
An array of rows, the rows data can be of any type.
topSummaryRows?: Maybe<readonly SR[]>
bottomSummaryRows?: Maybe<readonly SR[]>
An optional array of summary rows, usually used to display total values for example.
rowKeyGetter?: Maybe<(row: R) => K>
A function returning a unique key/identifier per row. rowKeyGetter
is required for row selection to work.
import DataGrid from 'react-data-grid';
interface Row {
id: number;
name: string;
}
function rowKeyGetter(row: Row) {
return row.id;
}
function MyGrid() {
return <DataGrid columns={columns} rows={rows} rowKeyGetter={rowKeyGetter} />;
}
:bulb: 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.
onRowsChange?: Maybe<(rows: R[], data: RowsChangeData<R, SR>) => void>
A function receiving row updates.
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';
function MyGrid() {
const [rows, setRows] = useState(initialRows);
return <DataGrid columns={columns} rows={rows} onRowsChange={setRows} />;
}
rowHeight?: Maybe<number | ((args: RowHeightArgs<R>) => number)>
Default: 35
pixels
Either a number defining the height of row in pixels, or a function returning dynamic row heights.
headerRowHeight?: Maybe<number>
Default: 35
pixels
A number defining the height of the header row.
summaryRowHeight?: Maybe<number>
Default: 35
pixels
A number defining the height of summary rows.
selectedRows?: Maybe<ReadonlySet<K>>
onSelectedRowsChange?: Maybe<(selectedRows: Set<K>) => void>
sortColumns?: Maybe<readonly SortColumn[]>
onSortColumnsChange?: Maybe<(sortColumns: SortColumn[]) => void>
defaultColumnOptions?: Maybe<DefaultColumnOptions<R, SR>>
groupBy?: Maybe<readonly string[]>
rowGrouper?: Maybe<(rows: readonly R[], columnKey: string) => Record<string, readonly R[]>>
expandedGroupIds?: Maybe<ReadonlySet<unknown>>
onExpandedGroupIdsChange?: Maybe<(expandedGroupIds: Set<unknown>) => void>
onFill?: Maybe<(event: FillEvent<R>) => R>
onCopy?: Maybe<(event: CopyEvent<R>) => void>
onPaste?: Maybe<(event: PasteEvent<R>) => R>
onRowClick?: Maybe<(row: R, column: CalculatedColumn<R, SR>) => void>
onRowDoubleClick?: Maybe<(row: R, column: CalculatedColumn<R, SR>) => void>
onScroll?: Maybe<(event: React.UIEvent<HTMLDivElement>) => void>
onColumnResize?: Maybe<(idx: number, width: number) => void>
cellNavigationMode?: Maybe<CellNavigationMode>
enableVirtualization?: Maybe<boolean>
renderers?: Maybe<Renderers<R, SR>>
This prop can be used to override the internal renderers. The prop accepts an object of type
interface Renderers<TRow, TSummaryRow> {
sortStatus?: Maybe<(props: SortStatusProps) => ReactNode>;
checkboxFormatter?: Maybe<
(props: CheckboxFormatterProps, ref: Ref<HTMLInputElement>) => ReactNode
>;
rowRenderer?: Maybe<(key: Key, props: RowRendererProps<TRow, TSummaryRow>) => ReactNode>;
noRowsFallback?: Maybe<ReactNode>;
}
For example, the default <Row />
component can be wrapped via the rowRenderer
prop to add context providers or tweak props
import DataGrid, { Row, RowRendererProps } from 'react-data-grid';
function myRowRenderer(key: React.Key, props: RowRendererProps<Row>) {
return (
<MyContext.Provider key={key} value={123}>
<Row {...props} />
</MyContext.Provider>
);
}
function MyGrid() {
return <DataGrid columns={columns} rows={rows} renderers={{ rowRenderer: myRowRenderer }} />;
}
:warning: To prevent all rows from being unmounted on re-renders, make sure to pass a static or memoized component to rowRenderer
.
rowClass?: Maybe<(row: R) => Maybe<string>>
direction?: Maybe<'ltr' | 'rtl'>
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 handle is shown on the left edge of the column
- Scrollbar is moved to the left
className?: string | undefined
style?: CSSProperties | undefined
'aria-label'?: string | undefined
'aria-labelledby'?: string | undefined
'aria-describedby'?: string | undefined
'data-testid'?: Maybe<string>
<TextEditor />
Props
See EditorProps
<Row />
See renderers
Props
See RowRendererProps
The ref
prop is supported.
<SortableHeaderCell />
Props
onSort: (ctrlClick: boolean) => void
sortDirection: SortDirection | undefined
priority: number | undefined
isCellSelected: boolean
children: React.ReactNode
<ValueFormatter />
Props
See FormatterProps
<SelectCellFormatter />
Props
value: boolean
isCellSelected: boolean
disabled?: boolean | undefined
onChange: (value: boolean, isShiftClick: boolean) => void
onClick?: MouseEventHandler<T> | undefined
'aria-label'?: string | undefined
'aria-labelledby'?: string | undefined
<ToggleGroupFormatter />
Props
Hooks
useRowSelection<R>(): [boolean, (selectRowEvent: SelectRowEvent<R>) => void]
Other
SelectColumn: Column<any, any>
SELECT_COLUMN_KEY = 'select-row'
Types
Column
DataGridHandle
EditorProps
FormatterProps
GroupFormatterProps
RowRendererProps
Generics
R
,TRow
: Row typeSR
,TSummaryRow
: Summary row typeK
: Row key type