The page provides an overview of and introduction to popular features available in AG Grid. Learn how to use Community features, configure and customise themes, and explore advanced Enterprise features.
![React Data Grid quick start video tutorial thumbnail](https://img.youtube.com/vi/6hxbPqziELk/0.jpg)
The following sections assume a level of familiarity with common Data Grid concepts. If you're new to React Data Grids in general, we recommend starting with our Introductory Tutorial instead.
Showing Data
Mapping Values
The field
or valueGetter
attributes Map Data to Columns. A field maps to a field in the data. A Value Getter is a function callback that returns the cell value.
The headerName
provides the title for the header. If missing the title is derived from field
.
const [columnDefs, setColumnDefs] = useState([
{ headerName: "Make & Model", valueGetter: p => p.make + ' ' + p.model},
{ field: "price" },
]);
<AgGridReact columnDefs={columnDefs} />
Text Formatting
Format text for cell content using a Value Formatter.
const [columnDefs, setColumnDefs] = useState([
{ field: "price", valueFormatter: p => '£' + p.value.toLocaleString() },
]);
<AgGridReact columnDefs={columnDefs} />
Cell Components
Add buttons, checkboxes or images to cells with a Cell Component.
const CustomButtonComponent = (props) => {
return <button onClick={() => window.alert('clicked') }>Push Me!</button>;
};
const [colDefs, setColDefs] = useState([
{ field: "button", cellRenderer: CustomButtonComponent },
// ...
]);
Resizing Columns
Columns are Resized by dragging the Column Header edges. Additionally assign flex
values to allow columns to flex to the grid width.
const [columnDefs, setColumnDefs] = useState([
{ field: "make", flex: 2 }, //This column will be twice as wide as the others
{ field: "model", flex: 1 },
{ field: "price", flex: 1 },
{ field: "electric", flex: 1 }
]);
<AgGridReact columnDefs={columnDefs} />
Example
This example demonstrates mapping and formatting values, cell components, and resizing columns.
Working with Data
By default, the row data is used to infer the Cell Data Type. The cell data type allows grid features, such as filtering and editing, to work without additional configuration.
Filtering
Column Filters are embedded into each column menu. These are enabled using the filter
attribute. The filter type is inferred from the cell data type.
const [columnDefs, setColumnDefs] = useState([
{ field: "make", filter: true },
]);
<AgGridReact columnDefs={columnDefs} />
There are 5 Provided Filters which can be set through this attribute. You can also create your own Custom Filter.
Floating Filters embed the Column Filter into the header for ease of access.
const [columnDefs, setColumnDefs] = useState([
{ field: "make", filter: true, floatingFilter: true },
]);
<AgGridReact columnDefs={columnDefs} />
Editing
Enable Editing by setting the editable
attribute to true
. The cell editor is inferred from the cell data type.
const [columnDefs, setColumnDefs] = useState([
{ field: "make", editable: true },
]);
<AgGridReact columnDefs={columnDefs} />
Set the cell editor type using the cellEditor
attribute. There are 7 Provided Cell Editors which can be set through this attribute. You can also create your own Custom Editors.
const [columnDefs, setColumnDefs] = useState([
{
field: "make",
editable: true,
cellEditor: 'agSelectCellEditor',
cellEditorParams: {
values: ['Tesla', 'Ford', 'Toyota'],
},
},
]);
<AgGridReact columnDefs={columnDefs} />
Sorting
Data is Sorted by clicking the column headers. Sorting is enabled by default.
Row Selection
Row Selection is enabled using the rowSelection
attribute.
// Column Definitions: Defines the columns to be displayed.
const [columnDefs, setColumnDefs] = useState([
{ field: "make" },
]);
const rowSelection = useMemo(() => {
return {
mode: 'multiRow',
};
}, []);
<AgGridReact
columnDefs={columnDefs}
rowSelection={rowSelection}
/>
Pagination
Enable Pagination by setting pagination
to be true.
const pagination = true;
const paginationPageSize = 500;
const paginationPageSizeSelector = [200, 500, 1000];
<AgGridReact
pagination={pagination}
paginationPageSize={paginationPageSize}
paginationPageSizeSelector={paginationPageSizeSelector}
/>
Example
This example demonstrates filtering, editing, sorting, row selection, and pagination.
Themes & Style
Themes
Grid Themes define how the grid looks (colors, font, spacing etc). The default theme is called Quartz. You can choose a different theme, or customise a built-in theme by changing parameters. Here we create a new theme based on Quartz:
import { themeQuartz } from "ag-grid-community"; // or themeBalham, themeAlpine
const myTheme = themeQuartz.withParams({
/* Low spacing = very compact */
spacing: 2,
/* Changes the color of the grid text */
foregroundColor: 'rgb(14, 68, 145)',
/* Changes the color of the grid background */
backgroundColor: 'rgb(241, 247, 255)',
/* Changes the header color of the top row */
headerBackgroundColor: 'rgb(228, 237, 250)',
/* Changes the hover color of the row*/
rowHoverColor: 'rgb(216, 226, 255)',
});
...
return (
<div>
<AgGridReact theme={myTheme} rowData={...} columnDefs={...} />
</div>
)
Theme Builder
Use the Theme Builder to create a custom theme with our visual editor. Browse and customise 100's of theme parameters and preview the changes in real-time. Automatically generate the theme code to copy & paste into your application.
Figma
If you are designing within Figma, you can use the AG Grid Design System to replicate the Quartz and Alpine AG Grid themes within Figma. These default themes can be extended with Figma variables to match any existing visual design or create entirely new AG Grid themes. These can then be exported and generated into new AG Grid themes.
Cell Style
Define rules to apply Styling to Cells using cellClassRules
. This can be used, for example, to set cell background colour based on its value.
.rag-green {
background-color: #33cc3344;
}
const [columnDefs, setColumnDefs] = useState([{
field: 'electric',
cellClassRules: {
// apply green to electric cars
'rag-green': params => params.value === true,
}
}]);
<AgGridReact columnDefs={columnDefs} />
Row Style
Define rules to apply Styling to Rows using rowClassRules
. This allows changing style (e.g. row colour) based on row values.
.rag-red {
background-color: #cc222244;
}
const rowClassRules = {
// apply red to Ford cars
'rag-red': params => params.data.make === 'Ford',
};
<AgGridReact rowClassRules={rowClassRules} />
Example
This example demonstrates cell style and row style.
Enterprise Features (e)
AG Grid comes in two forms:
- AG Grid Community: Free for everyone, including production use - no license required.
- AG Grid Enterprise: Requires a license to use in production. Free to test locally, or request a trial to test in production.
To learn more about the differences between AG Grid Community and Enterprise, when to use each version, and how to access our free trial or purchase a license, see the Community vs Enterprise docs.
Integrated Charts (e)
Integrated Charts allow users to build and customise charts directly within the grid.
Enable Integrated Charts by setting enableCharts
to true
. Set cellSelection
to true
to allow users to create charts by selecting a range of cells:
const enableCharts = true;
const cellSelection = true;
<AgGridReact
enableCharts={enableCharts}
cellSelection={cellSelection}
/>
Grouping Rows (e)
Enable Row Grouping by setting rowGroup
to true
:
const [columnDefs, setColumnDefs] = useState([
{ field: 'country', rowGroup: true },
// ...
]);
<AgGridReact columnDefs={columnDefs} />
Aggregating Rows (e)
Enable Aggregation by setting aggFunc
to one of sum
, min
, max
, count
, avg
, first
, or last
:
const [columnDefs, setColumnDefs] = useState([
{ field: 'gold', aggFunc: 'sum' },
// ...
]);
<AgGridReact columnDefs={columnDefs} />
Pivoting Rows (e)
Enable Pivoting by setting pivotMode
to true
. Define pivot columns by setting pivot
to true
:
const [columnDefs, setColumnDefs] = useState([
{ field: 'sport', pivot: true },
]);
const pivotMode = true;
<AgGridReact
columnDefs={columnDefs}
pivotMode={pivotMode}
/>
Displaying Tree Data (e)
Tree Data provides a way to supply the grid with structured hierarchical data.
Enable Tree Data by setting treeData
to true
. Provide a getDataPath
callback to configure the Row Hierarchy:
const treeData = true;
const getDataPath = useCallback(data => data.path, []);
<AgGridReact
treeData={treeData}
getDataPath={getDataPath}
/>
Displaying Tool Panels (e)
The grid provides Tool Panels for Columns and Filters. You can also provide Custom Tool Panels.
To enable Column and Filter Tool Panels, set sideBar
to true
. To display only the Column or Filter Tool Panel, set sideBar
to 'columns'
or 'filters'
:
const sideBar = true;
<AgGridReact sideBar={sideBar} />
Example
This example demonstrates Integrated Charting, Row Grouping, Pivoting, Aggregation and Tool Panels: