React Data GridCustom Components
react logo

The full list of component types you can provide in AG Grid are as follows:

The remainder of this page gives information that is common across all the component types.

Registering Custom Components

For all custom components, you should enable the grid option reactiveCustomComponents. This provides the simplest way to set up custom components when using Hooks.

If your custom component was built in an imperative way instead of setting the reactiveCustomComponents option, it needs to be rebuilt to take advantage of the new features that reactiveCustomComponents offers. Using custom components built in an imperative way is now deprecated, and in AG Grid v32 the reactiveCustomComponents option will be true by default. See Migrating to Use reactiveCustomComponents.

There are two ways to register custom components:

  • Direct reference.
  • By name.

1. By Direct Reference

When registering a React Component by reference you simply pass the Component to the place you want it used (i.e. Cell Renderer, Filter etc).

In this example we're specifying that we want our React CubeComponent as a Cell Renderer in the Cube column:

//...other imports
import CubeComponent from './CubeComponent';

const GridExample = () => {
   // other properties & methods
   
    const columnDefs = useMemo( () => [{field: 'value', cellRenderer: CubeComponent}], []);

    return (
         <AgGridReact
            columnDefs={columnDefs}
            ...other properties            
         />
    );
};

The advantage of referencing Components directly is cleaner code, without the extra level of indirection added when referencing by name.

2. By Name

When registering a React component by name you need to first register the component within the grid components property, then reference the component by name where you want it used (i.e. as a Cell Renderer, Filter etc).

In this example we've registered our React CubeComponent and given it a name of cubeComponent (this can be any name you choose). We then specify that we want the previously registered cubeComponent to be used as a Cell Renderer in the Cube column:

//...other imports
import CubeComponent from './CubeComponent';

const GridExample = () => {
   // other properties & methods
   
   const components = useMemo(() => ({
       cubeComponent: CubeComponent    
   }), []);

   const columnDefs = useMemo(() => [{field: 'value', cellRenderer: 'cubeComponent'}], []);

   return (
         <AgGridReact
            components={components}
            columnDefs={columnDefs}
            ...other properties            
         />
   );
};

The advantage of referencing components by name is definitions (eg Column Definitions) can be composed of simple types (ie JSON), which is useful should you wish to persist Column Definitions.

A React Component in this context can be any valid React Component - A Class Based Component, a Hook or even an inline Functional Component. The same rules apply regardless of the type of component used.

Providing Additional Parameters

Each Custom Component gets a set of parameters from the grid. For example, for Cell Renderer the grid provides, among other things, the value to be rendered. You can provide additional properties to the Custom Component (e.g. what currency symbol to use) by providing additional parameters specific to your application.

To provide additional parameters, use the property [prop-name]Params, e.g. cellRendererParams.

const [columnDefs, setColumnDefs] = useState([
    { 
        field: 'price',
        cellRenderer: PriceCellRenderer,
        cellRendererParams: {
            currency: 'EUR'
        }
    },
]);

<AgGridReact columnDefs={columnDefs} />

Mixing JavaScript and React

When providing Custom Components you have a choice of the following:

  1. Provide an AG Grid component as a React Component.
  2. Provide an AG Grid component in JavaScript (JavaScript Class Components only, not JavaScript Functional Components).

The following code snippet shows how both JavaScript and React Components can be used at the same time:

//...other imports
import JavascriptComponent from './JavascriptComponent.js';
import ReactComponent from './ReactComponent';

const GridExample = () => {
   // JS and React components, only need register if looking up by name
   const components = useMemo(() => ({
       'javascriptComponent': JavascriptComponent,
       'reactComponent': ReactComponent    
   }), []);

   const columnDefs = useMemo( () => [
       {
           headerName: "JS Cell",
           field: "value",
           cellRenderer: 'javascriptComponent', // JS comp by Name
       },
       {
           headerName: "JS Cell",
           field: "value",
           cellRenderer: JavascriptComponent, // JS comp by Direct Reference
       },
       {
           headerName: "React Cell",
           field: "value",
           cellRenderer: 'reactComponent', // React comp by Name
       },
       {
           headerName: "React Cell",
           field: "value",
           cellRenderer: ReactComponent, // React comp by Direct Reference
       }
   ], []);

    return (
        <div className="ag-theme-quartz">
            <AgGridReact
               components={components}
               columnDefs={columnDefs}
               ...other properties
            />
        </div>
    );
};
Change the documentation view to JavaScript to see how to create a plain JavaScript component.

JavaScript Functional Components

Function Components are not supported by AG Grid React. This is because the grid has no way to distinguish JavaScript Functional Components from React Functional Components. The grid identifies a JavaScript Class Component by looking for the getGui() method. If this method is missing, it assumes a React Component. Thus all functions will be treated as React Components / Hooks.

Component Usage

The below table gives a summary of the components, where they are configured and using what attribute.

ComponentWhereAttribute
Cell RendererColumn DefinitioncellRenderer
cellRendererParams
cellRendererSelector
Cell EditorColumn DefinitioncellEditor
cellEditorParams
cellEditorSelector
FilterColumn Definitionfilter
filterParams
Floating FilterColumn DefinitionfloatingFilter
floatingFilterParams
Header ComponentColumn DefinitionheaderComponent
headerComponentParams
Header Group ComponentColumn DefinitionheaderGroupComponent
headerGroupComponentParams
Tooltip ComponentColumn DefinitiontooltipComponent
tooltipComponentParams
Group Row Cell RendererGrid OptiongroupRowRenderer
groupRowRendererParams
Group Row Inner Cell RendererGrid OptioninnerRenderer
innerRendererParams
Detail Cell RendererGrid OptiondetailCellRenderer
detailCellRendererParams
Full Width Cell RendererGrid OptionfullWidthCellRenderer
fullWidthCellRendererParams
Loading Cell RendererGrid OptionloadingCellRenderer
loadingCellRendererParams
Loading OverlayGrid OptionloadingOverlayComponent
loadingOverlayComponentParams
No Rows OverlayGrid OptionnoRowsOverlayComponent
noRowsOverlayComponentParams
Date ComponentGrid OptiondateComponent
dateComponentParams
Status Bar ComponentGrid Option -> Status BarstatusPanel
statusPanelParams
Tool PanelGrid Option -> Side BartoolPanel
toolPanelParams
Menu ItemGrid Option -> MenumenuItem
menuItemParams

Grid Provided Components

The grid comes with pre-registered components that can be used. Each component provided by the grid starts with the namespaces 'ag' to minimise naming conflicts with user provided components. The full list of grid provided components are in the table below.

Date Inputs

agDateInputDefault date input used by filters.

Column Headers

agColumnHeaderDefault column header.
agColumnHeaderGroupDefault column group header.

Column Filters

agSetColumnFilterSet filter (default when using AG Grid Enterprise).
agTextColumnFilterSimple text filter (default when using AG Grid Community).
agNumberColumnFilterNumber filter.
agDateColumnFilterDate filter.
agMultiColumnFilterMulti filter.
agGroupColumnFilterGroup column filter.

Floating Filters

agSetColumnFloatingFilterFloating set filter.
agTextColumnFloatingFilterFloating text filter.
agNumberColumnFloatingFilterFloating number filter.
agDateColumnFloatingFilterFloating date filter.
agMultiColumnFloatingFilterFloating multi filter.
agGroupColumnFloatingFilterFloating group column filter.

Cell Renderers

agAnimateShowChangeCellRendererCell renderer that animates value changes.
agAnimateSlideCellRendererCell renderer that animates value changes.
agGroupCellRendererCell renderer for displaying group information.
agLoadingCellRendererCell renderer for loading row when using Enterprise row model.
agCheckboxCellRendererCell renderer that displays a checkbox for boolean values.

Overlays

agLoadingOverlayLoading overlay.
agNoRowsOverlayNo rows overlay.

Cell Editors

agTextCellEditorText cell editor.
agSelectCellEditorSelect cell editor.
agRichSelectCellEditorRich select editor.
agLargeTextCellEditorLarge text cell editor.
agNumberCellEditorNumber cell editor.
agDateCellEditorDate cell editor.
agDateStringCellEditorDate represented as string cell editor.
agCheckboxCellEditorCheckbox cell editor.

Master Detail

agDetailCellRendererDetail panel for master / detail grid.

Column Menu / Context Menu

agMenuItemMenu item within column or context menu

Overriding Grid Components

It is also possible to override components. Where the grid uses a default value, this means the override component will be used instead. The default components, where overriding makes sense, are as follows:

  • agDateInput: To change the default date selection across all filters.
  • agColumnHeader: To change the default column header across all columns.
  • agColumnGroupHeader: To change the default column group header across all columns.
  • agLoadingCellRenderer: To change the default loading cell renderer for Enterprise Row Model.
  • agLoadingOverlay: To change the default 'loading' overlay.
  • agNoRowsOverlay: To change the default loading 'no rows' overlay.
  • agCellEditor: To change the default cell editor.
  • agDetailCellRenderer: To change the default detail panel for master / detail grids.
  • agMenuItem: To change the default menu item for column and context menus.

To override the default component, register the custom component in the GridOptions components property under the above name.

const components = useMemo(() => (
    { agDateInput: CustomDateComponent,
      agColumnHeader: CustomHeaderComponent 
    }), []);

<AgGridReact
    components={components}
    ...other properties...
/>