Infinite Table React DataGrid
website·Indexed 32 days ago
https://infinite-table.com/docsA high-performance React DataGrid component featuring advanced column management, Excel-like inline editing, client-side and server-side filtering, and complex grouping and pivoting capabilities. Includes support for custom column rendering via hooks like useInfiniteColumnCell and useInfiniteHeaderCell, as well as flexible aggregation and pivot column customization.
What's inside Infinite Table
- Infinite Table is a React DataGrid component designed to balance the trade-offs between full-featured grids (like AG Grid) and headless UI libraries (like TanStack Table). It provides a ready-to-use component (not headless) to accelerate development speed while maintaining a fully declarative API. Unlike imperative grids, updates to the table are handled by changing props, ensuring it integrates naturally with the React mental model.
Understand the Inline Editing lifecycle flow
The inline editing process follows this sequence of operations:
- Trigger:
startEditis called (API or User). - Editability Check: The table checks if the cell is editable (async checks supported).
- Value Retrieval: The value to be edited is retrieved via
column.getValueToEdit. - Active Editing: The user modifies the value.
- Stopping the Edit:
stopEditis called, resulting in one of three states:- Cancelled: Value is discarded $\rightarrow$
onEditCancelled()is triggered. - Rejected: Value is rejected with an error $\rightarrow$
onEditRejected()is triggered. - Accepted: Value is passed to the persist layer $\rightarrow$
onEditAccepted()is triggered.
- Cancelled: Value is discarded $\rightarrow$
- Persistence:
- If
props.persistEditis defined, it is called (async). - Otherwise, it defaults to
dataSourceApi.updateData(...).
- If
- Final Notification: Depending on the persistence result, either
onEditPersistSuccess()oronEditPersistError()is called.
- Trigger:
Retrieve cell information using useInfiniteColumnCell
The
useInfiniteColumnCellhook is used withincolumns.render,column.components.ColumnCell, or other rendering functions to retrieve information about the cell currently being rendered.Important Implementation Details:
- When used inside a custom column cell component (
column.components.ColumnCell), you must extractdomReffrom the hook result and apply it to the root DOM element of the component. - When used inside
columns.renderorcolumns.renderValue, you should NOT pass thedomRefto the element.
import { useInfiniteColumnCell } from '@infinite-table/infinite-react'; const CustomCellComponent = (props: React.HTMLProps<HTMLDivElement>) => { // Extract domRef and other cell data const { domRef, value, data } = useInfiniteColumnCell<Developer>(); return ( <div ref={domRef} {...props} style={{ ...props.style, color: 'red' }}> {props.children} </div> ); };- When used inside a custom column cell component (
Handle large datasets with row and column virtualization
Infinite Table maintains performance with large datasets (e.g., 10,000 rows and 12+ columns) by utilizing virtualization for both rows and columns. This ensures that adding more columns does not degrade performance and prevents white space from appearing during horizontal or vertical scrolling.import { InfiniteTable, DataSource } from '@infinite-table/infinite-react'; // Example setup for 10k rows <DataSource<Employee> data={dataSource} primaryKey="id"> <InfiniteTable<Employee> debugId="many-rows-and-columns-example" columns={columns} columnDefaultWidth={150} /> </DataSource>Handle cell click events with onCellClick
TheonCellClickcallback is triggered whenever a cell in the Infinite Table is clicked. It provides detailed context about the clicked cell, including its row and column indices, the column definition, and references to the Column, Table, and Data Source APIs. The second argument provided to the callback is the native browser click event.onCellClick(({ colIndex, rowIndex, column, columnApi, api, dataSourceApi }, event) => { console.log(`Cell clicked at row ${rowIndex}, column ${colIndex}`); // Use dataSourceApi to fetch data or api to manipulate the table })Compare Infinite Table and MUI X Data Grid architecture
Infinite Table and MUI X Data Grid are both React-based data grids using declarative, prop-driven APIs and JSX cell renderers. However, they differ significantly in their architectural approach to design systems and data management:
- Design System Coupling: MUI X Data Grid is tightly coupled to Material UI and requires the MUI styling infrastructure (
@emotion, theme provider). Infinite Table is design-system agnostic and uses CSS variables, making it compatible with Tailwind, vanilla CSS, or any other system without extra dependencies. - Component Model: Infinite Table separates data management from rendering using two components:
<DataSource>(handles fetching, sorting, grouping, pivoting, and filtering) and<InfiniteTable>(handles rendering). MUI X Data Grid uses a single component (<DataGrid>,<DataGridPro>, or<DataGridPremium>) to handle both. - Virtualization: Infinite Table provides both row and column virtualization by default. MUI X Community only virtualizes rows (up to 100); column virtualization requires the Pro tier or higher.
- Design System Coupling: MUI X Data Grid is tightly coupled to Material UI and requires the MUI styling infrastructure (
Compare Infinite Table and TanStack Table architectures
Infinite Table and TanStack Table represent two different approaches to building data tables in React:
- Infinite Table is a rendered React component. It provides a complete UI including a virtualized grid, headers, cells, scrollbars, keyboard navigation, and theming out of the box. It uses a declarative API where you pass props (columns, data, grouping) and the grid handles the rendering and DOM management.
- TanStack Table is a headless logic library. It provides the state and utilities for sorting, filtering, grouping, and pagination, but provides no UI. The developer is responsible for writing all JSX, CSS, virtualization (e.g., via TanStack Virtual), and accessibility/ARIA attributes.
Key Architectural Differences:
- Virtualization: Built-in for Infinite Table; requires external libraries (like TanStack Virtual) for TanStack Table.
- Framework Support: Infinite Table is React-only; TanStack Table supports React, Vue, Solid, and Svelte.
- Bundle: Infinite Table is a single package including CSS; TanStack Table has a tiny core, with total size depending on the UI implementation built on top of it.
Understand the rowInfo object for ungrouped tables
In scenarios where no grouping is defined, therowInfoobject provides metadata about the current row. It is used by functions likecolumns.render,rowStyle, androwClassNameto determine how to render cells or rows.// Discriminator for ungrouped scenario if (rowInfo.dataSourceHasGrouping === false) { // Access properties: // rowInfo.data: The row data // rowInfo.id: Row ID defined by idProperty // rowInfo.indexInAll: Index in the full dataset // rowInfo.selfLoaded: Boolean for lazy-loading batching indicators }InfiniteTableColumnCellContextType Reference
The
InfiniteTableColumnCellContextTypeis the type used for the parameter ofcolumns.renderValue(and related rendering functions) and is the object returned by theuseInfiniteColumnCellhook. It provides comprehensive context about the cell, row, and table state during rendering.Properties:
isGroupRow(boolean): Indicates if the current row is a group row.data(DATA_TYPE | Partial<DATA_TYPE> | null): The data object for the current row. IfisGroupRowisfalse, it is of typeDATA_TYPE. For group rows, it may be a partial object containing aggregated values or null.rowInfo(InfiniteTableRowInfo): Detailed information about the current row.rawValue(string | number | other): The raw cell value computed from the columnfieldorvalueGetterfunction.value(Renderable): The value to render. This is therawValueprocessed by the columnvalueFormatterif one exists.column(InfiniteTableComputedColumn): The computed column definition for the current cell.columnsMap: A map ofInfiniteTableComputedColumnobjects keyed by column ID.fieldsToColumn: A map ofInfiniteTableComputedColumnobjects keyed by the column field (excludes columns not bound to a field).align("start" | "center" | "end"): The computed alignment for the current cell.api(InfiniteTableApi): The table API object.rowIndex(number): The index of the current row.renderBag: Context for the column rendering pipeline.toggleCurrentGroupRow(() => void): Function to toggle the current row if it is a group row.toggleCurrentTreeNode(() => void): Function to toggle the expand/collapse state of the current tree node (Tree Grid only).rootGroupBy(DataSourceGroupBy): The group-by configuration specified in theDataSourcegroupByprop.groupByForColumn: Available for group columns.- If
groupRenderStrategyis"multi-column", this is a singleDataSourcePropGroupByfor each generated group column. - If
groupRenderStrategyis"single-column", this is an array ofDataSourcePropGroupByobjects, available only in the single generated group column.
- If
InfiniteTableRowInfo type definition
TheInfiniteTableRowInfoobject is passed to styling functions in Infinite Table to provide context about the row being rendered. It includes properties for identification (id), data access (data), positioning (indexInAll,indexInGroup), and grouping state (groupBy,isGroupRow,collapsed).Access master row data in RowDetail with useMasterRowInfo
TheuseMasterRowInfohook is used inside acomponents.RowDetailcomponent to retrieve information about the master row that is currently being detailed. This is essential for implementing dependent data loading (e.g., loading developers for a specific city).function RowDetail() { const rowInfo = useMasterRowInfo<City>()!; console.log('rendering detail for master row', rowInfo.id); // rowInfo.data contains the full data object for the master row return <div>Details for {rowInfo.data.name}</div>; }Compare Infinite Table with other React Data Grids
Infinite Table is a React-native data grid focusing on a small, composable API surface using declarative props and JSX renderers. It includes grouping, pivoting, and tree data in its free tier.
Key alternatives include:
- AG Grid: A multi-framework enterprise grid with the widest feature set (charting, server-side row models) but uses a more imperative API.
- TanStack Table: A headless logic library. It provides no UI or virtualization; the developer must build the rendering layer.
- MUI X Data Grid: Deeply integrated with Material UI. Features like grouping and pivoting require paid Pro/Premium tiers.