AG Grid React: Complete Tutorial for High-Performance Data Grids
A practical, no-nonsense guide to installation, configuration, sorting, filtering, pagination, cell editing and performance tuning for AG Grid in React.
Overview: Why choose AG Grid for React data grids?
AG Grid is a mature React data grid library designed for enterprise-level applications where performance, customization and data operations matter. Unlike lightweight table components, AG Grid brings built-in features such as virtualization, server-side row models, advanced filtering, group/aggregation, and rich cell rendering—so you don't have to rebuild them.
From a development perspective, AG Grid's React integration is component-first and idiomatic: you pass columnDefs and rowData, plug in cell renderers or editors as React components, and handle grid events for full control. That makes it a top choice if you need an interactive table React solution that scales.
Use cases range from dashboards and reporting to financial screens and spreadsheets. If you search for "AG Grid React example", you'll find many practical demos; a solid community tutorial to get started is available here: AG Grid tutorial. For official docs and deeper API references, see the AG Grid docs: AG Grid React docs.
Quick setup: AG Grid installation and React setup
Install the core packages for a basic AG Grid React project. Use npm or yarn:
// npm
npm install --save ag-grid-community ag-grid-react
// or yarn
yarn add ag-grid-community ag-grid-react
Import the styles and the React wrapper in your component. Minimal example:
import 'ag-grid-community/styles/ag-grid.css';
import 'ag-grid-community/styles/ag-theme-alpine.css';
import { AgGridReact } from 'ag-grid-react';
Then render the grid with columnDefs and rowData properties. The grid will render quickly for small- to medium-sized datasets; for large datasets, switch rowModel to 'infinite' or 'serverSide' and implement a backend data source for pagination/virtualization.
Tip: include a canonical CSS theme (alpine, balham, etc.)—it affects layout, floating filters and theming behavior.
Core features: Sorting, filtering, pagination and cell editing
AG Grid exposes feature toggles primarily at the column and grid level. To enable sorting and filtering, set them on each column or via defaultColDef:
const defaultColDef = { sortable: true, filter: true, resizable: true };
Pagination is simple for client-side datasets—set pagination: true and paginationPageSize. For large datasets, use the infinite or server-side row model to fetch only the rows you need. The grid's pagination UI supports quick navigation and page size changes out of the box.
Cell editing: columns accept editable: true and custom cell editors. Capture changes with onCellValueChanged or onCellEditingStopped to synchronize local state or dispatch updates to a server. AG Grid supports built-in editors (text, select, large text) and you can embed a full React component as a cell editor for complex UI.
Example: enabling editing and capturing edits:
<AgGridReact
rowData={rowData}
columnDefs={columnDefs}
defaultColDef={{ editable: true }}
onCellValueChanged={handleCellChanged}
/>
Advanced patterns: Custom renderers, virtualization, server-side pagination
To build interactive table React experiences, use custom cell renderers (React components) to show buttons, icons, formatted values, or nested components. Renderers can receive the cell value, row data, and grid APIs for full interaction.
Virtualization is essential for performance. AG Grid's default row model virtualizes rows and columns where possible, but for huge datasets leverage the 'infinite' or 'serverSide' rowModel. With server-side row model you can paginate, group, and aggregate on the server—AG Grid will request only the slices it needs.
Typical server-side flow: user filters or changes page ► grid issues a datasource request with sort/filter info ► server responds with rows and total count ► grid renders those rows. This keeps the React data table performant and responsive even for millions of rows.
Use cases such as spreadsheets can be handled with rich cell editors and clipboard support; AG Grid even supports Excel export/import capabilities for interoperability with spreadsheet workflows.
Performance and best practices
Performance tuning is where AG Grid really shines—but it requires configuration. Prefer immutable data patterns with deltaRowDataMode when updating row sets from props, which lets the grid perform fast diffs. Also keep columnDefs stable (useMemo/useCallback) to avoid reinitializing column state on every render.
Key props to consider: rowBuffer, rowSelection, suppressRowClickSelection, and rowModel. Avoid expensive render work inside cell renderers—memoize renderer components and only read the props you need. For very large datasets, offload grouping, filtering and aggregation to the server.
Profiling tips: enable the grid's debug logs briefly to see rendering counts, or use React DevTools to inspect unnecessary re-renders. When done correctly, AG Grid can display tens of thousands of rows with sub-second interactions.
Examples and minimal code
Here's a compact React example that wires up basics: installation, columnDefs, sorting, filtering, pagination and editing. This is ready to paste into a create-react-app component file:
import React, { useState, useMemo } from 'react';
import 'ag-grid-community/styles/ag-grid.css';
import 'ag-grid-community/styles/ag-theme-alpine.css';
import { AgGridReact } from 'ag-grid-react';
export default function GridExample() {
const [rowData] = useState([
{ id:1, name:'Alice', age:30 },
{ id:2, name:'Bob', age:24 },
{ id:3, name:'Carol', age:29 }
]);
const columnDefs = useMemo(() => ([
{ field: 'id', sortable: true, filter: 'agNumberColumnFilter' },
{ field: 'name', sortable: true, filter: true, editable: true },
{ field: 'age', sortable: true, filter: 'agNumberColumnFilter', editable: true }
]), []);
function onCellValueChanged(params){
console.log('changed', params.data);
}
return (
<div className="ag-theme-alpine" style={{height:400, width:'100%'}}>
<AgGridReact
rowData={rowData}
columnDefs={columnDefs}
defaultColDef={{ resizable: true }}
pagination={true}
paginationPageSize={10}
onCellValueChanged={onCellValueChanged}
/>
</div>
);
}
This example demonstrates the common pattern for most small apps. For production you'll likely add remote row models, column state persistence, and custom editors/renderers as business requirements dictate.
Integrations, troubleshooting and resources
Common integration points include state management libraries, React Query for data fetching, and form libraries when editing grid rows. If you need Excel-like behavior, check AG Grid's enterprise features (license required) for advanced export, pivoting and charts.
When troubleshooting rendering or event issues: (1) ensure styles are imported; (2) confirm you're using compatible package versions between ag-grid-community and ag-grid-react; (3) wrap columnDefs and grid callbacks in useMemo/useCallback to avoid unnecessary rebuilds.
Further resources: the official AG Grid docs are comprehensive and include many React examples (AG Grid React docs). For community tutorials and extended walkthroughs, here's a hands-on guide: AG Grid tutorial. For general React guidance, see the React docs: React documentation.
FAQ
How do I install AG Grid in React?
Install ag-grid-community and ag-grid-react via npm or yarn, import the CSS theme (e.g., alpine) and use the AgGridReact component with columnDefs and rowData. For example: npm install ag-grid-community ag-grid-react, import the styles and mount the grid.
How do I implement sorting, filtering and pagination in AG Grid React?
Enable sorting and filtering on columns (or in defaultColDef) with sortable: true and filter: true. For pagination, set pagination: true and a page size. For very large datasets, use the 'infinite' or 'serverSide' row models to fetch and display only required rows.
How do I enable cell editing and capture edited values?
Mark columns with editable: true, provide custom editors if needed, and listen to events such as onCellValueChanged or onCellEditingStopped to persist changes to local state or send updates to a backend.
Semantic Core (Primary, Secondary, Clarifying)
This semantic core groups relevant queries and LSI phrases to guide on-page optimization and voice-search coverage.
Primary keywords
AG Grid React, React data grid, AG Grid tutorial, React table component, AG Grid installation, React data table, AG Grid React example, interactive table React
Secondary keywords
AG Grid filtering sorting, AG Grid pagination, AG Grid cell editing, React grid component, React spreadsheet table, React data grid library, AG Grid React setup, React data table library
Clarifying / Long-tail / LSI
install ag-grid react, ag-grid react example code, how to enable sorting in ag-grid, server-side pagination ag-grid react, ag-grid cell renderer react, ag-grid editable cells, ag-grid performance tips, ag-grid deltaRowDataMode
Micro-markup recommendation
Include FAQ schema (JSON-LD) for the three FAQ Q&As above to increase the chance of appearing in rich results. The page already contains an example JSON-LD block in the head. If you publish multiple FAQs, update the JSON-LD array accordingly.
Backlinks used in this article
Embedded resource links relevant to the topic:
- AG Grid tutorial (example walkthrough)
- AG Grid React docs (official documentation)
- React documentation (React basics)