---
title: "Row Grouping - Custom Group Columns"
enterprise: true
framework: react
version: "36.1.0"
---

# Row Grouping - Custom Group Columns

Custom Group Columns can be provided to gain additional control over the group columns.

> **Warning**
>
> We advise against using your own group columns. Only do this if you require:
>
> - The ability to position a column left of the group column, and `colDef.lockPosition` or `colDef.pinned` are insufficient.
> - Fine grain control of [Multiple Group Columns](https://www.ag-grid.com/react-data-grid/grouping-multiple-group-columns/) configuration per column, where callbacks are unsupported.

## Enabling a Single Custom Group Column

A [Single Group Column](https://www.ag-grid.com/react-data-grid/grouping-single-group-column/) can be configured by setting the `groupDisplayType` grid option to `"custom"`. The column displaying groups then needs to also be included in the `columnDefs` with `colDef.showRowGroup` set to `true`, and the `cellRenderer` set to `'agGroupCellRenderer'`.

#### Custom Grouping Single Group Column

```tsx
"use client";

import React, {
  useCallback,
  useMemo,
  useRef,
  useState,
  StrictMode,
} from "react";
import { createRoot } from "react-dom/client";
import { AgGridReact, AgGridProvider } from "ag-grid-react";
import {
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  GridApi,
  GridOptions,
  ModuleRegistry,
  RowGroupingDisplayType,
  enableDevValidations,
} from "ag-grid-community";
import { RowGroupingModule } from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";
import { useFetchJson } from "./useFetchJson";

if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

const modules = [ClientSideRowModelModule, RowGroupingModule];

const GridExample = () => {
  const containerStyle = useMemo(() => ({ width: "100%", height: "100%" }), []);
  const gridStyle = useMemo(() => ({ height: "100%", width: "100%" }), []);

  const [columnDefs, setColumnDefs] = useState<ColDef[]>([
    // one column for showing the groups
    {
      headerName: "Group",
      cellRenderer: "agGroupCellRenderer",
      showRowGroup: true,
      minWidth: 210,
    },
    // the first group column
    { field: "country", rowGroup: true, hide: true },
    { field: "year", rowGroup: true, hide: true },
    { field: "athlete" },
    { field: "total" },
  ]);
  const defaultColDef = useMemo<ColDef>(() => {
    return {
      flex: 1,
      minWidth: 200,
    };
  }, []);

  const { data, loading } = useFetchJson<IOlympicData>(
    "https://www.ag-grid.com/example-assets/olympic-winners.json",
  );

  return (
    <AgGridProvider modules={modules}>
      <div style={containerStyle}>
        <div style={gridStyle}>
          <AgGridReact<IOlympicData>
            rowData={data}
            loading={loading}
            columnDefs={columnDefs}
            defaultColDef={defaultColDef}
            groupDisplayType={"custom"}
          />
        </div>
      </div>
    </AgGridProvider>
  );
};

const root = createRoot(document.getElementById("root")!);
root.render(
  <StrictMode>
    <GridExample />
  </StrictMode>,
);
```

[Live example: Custom Grouping Single Group Column](https://www.ag-grid.com/examples/grouping-custom-group-columns/custom-grouping-single-group-column/reactFunctionalTs)

The example above demonstrates the following configuration:

```jsx
const [columnDefs, setColumnDefs] = useState([
    { field: 'country', rowGroup: true, hide: true },
    { field: 'year', rowGroup: true, hide: true },
    { headerName: 'Groups', showRowGroup: true, cellRenderer: 'agGroupCellRenderer' },
    // ...other column definitions
]);
const groupDisplayType = 'custom';

<AgGridReact
    columnDefs={columnDefs}
    groupDisplayType={groupDisplayType}
/>
```

## Enabling Multiple Custom Group Columns

[Multiple Group Columns](https://www.ag-grid.com/react-data-grid/grouping-multiple-group-columns/) can be configured by setting the `groupDisplayType` grid option to `"custom"`.

Each column displaying groups needs to be included in the `columnDefs` with `colDef.showRowGroup` set to the `colId` of the grouped column they are displaying. The `colDef` also requires `cellRenderer` to be set to `'agGroupCellRenderer'`.

#### Custom Grouping Multiple Group Columns

```tsx
"use client";

import React, {
  useCallback,
  useMemo,
  useRef,
  useState,
  StrictMode,
} from "react";
import { createRoot } from "react-dom/client";
import { AgGridReact, AgGridProvider } from "ag-grid-react";
import {
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  GridApi,
  GridOptions,
  ModuleRegistry,
  RowGroupingDisplayType,
  enableDevValidations,
} from "ag-grid-community";
import { RowGroupingModule } from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";
import { useFetchJson } from "./useFetchJson";

if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

const modules = [ClientSideRowModelModule, RowGroupingModule];

const GridExample = () => {
  const containerStyle = useMemo(() => ({ width: "100%", height: "100%" }), []);
  const gridStyle = useMemo(() => ({ height: "100%", width: "100%" }), []);

  const [columnDefs, setColumnDefs] = useState<ColDef[]>([
    {
      headerName: "Country Groups",
      minWidth: 200,
      showRowGroup: "country",
      cellRenderer: "agGroupCellRenderer",
    },
    {
      headerName: "Year Groups",
      minWidth: 200,
      showRowGroup: "year",
      cellRenderer: "agGroupCellRenderer",
    },
    { field: "country", rowGroup: true, hide: true },
    { field: "year", rowGroup: true, hide: true },
    { field: "athlete", minWidth: 220 },
    { field: "total" },
  ]);
  const defaultColDef = useMemo<ColDef>(() => {
    return {
      flex: 1,
      minWidth: 150,
    };
  }, []);

  const { data, loading } = useFetchJson<IOlympicData>(
    "https://www.ag-grid.com/example-assets/olympic-winners.json",
  );

  return (
    <AgGridProvider modules={modules}>
      <div style={containerStyle}>
        <div style={gridStyle}>
          <AgGridReact<IOlympicData>
            rowData={data}
            loading={loading}
            columnDefs={columnDefs}
            defaultColDef={defaultColDef}
            groupDisplayType={"custom"}
          />
        </div>
      </div>
    </AgGridProvider>
  );
};

const root = createRoot(document.getElementById("root")!);
root.render(
  <StrictMode>
    <GridExample />
  </StrictMode>,
);
```

[Live example: Custom Grouping Multiple Group Columns](https://www.ag-grid.com/examples/grouping-custom-group-columns/custom-grouping-many-group-columns/reactFunctionalTs)

The example above demonstrates the following configuration for configuring multiple groups columns:

```jsx
const [columnDefs, setColumnDefs] = useState([
    { colId: 'country', field: 'country', rowGroup: true, hide: true },
    { colId: 'year',  field: 'year', rowGroup: true, hide: true },
    { headerName: 'Country Groups', showRowGroup: 'country', cellRenderer: 'agGroupCellRenderer', },
    { headerName: 'Year Groups', showRowGroup: 'year', cellRenderer: 'agGroupCellRenderer', },
    // ...other column definitions
]);
const groupDisplayType = 'custom';

<AgGridReact
    columnDefs={columnDefs}
    groupDisplayType={groupDisplayType}
/>
```
