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

# Row Grouping - Row Group Panel

Use the Row Group Panel to enable users to modify the configured row group columns.

#### Enabling Row Group Panel

```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 {
  AutoGroupColumnDef,
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  GridApi,
  GridOptions,
  ModuleRegistry,
  enableDevValidations,
} from "ag-grid-community";
import { RowGroupingModule, RowGroupingPanelModule } from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";
import { useFetchJson } from "./useFetchJson";

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

const modules = [
  ClientSideRowModelModule,
  RowGroupingModule,
  RowGroupingPanelModule,
];

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

  const [columnDefs, setColumnDefs] = useState<ColDef[]>([
    { field: "country", rowGroup: true, enableRowGroup: true, hide: true },
    { field: "year", rowGroup: true, enableRowGroup: true, hide: true },
    { field: "sport", enableRowGroup: true },
    { field: "total" },
  ]);
  const defaultColDef = useMemo<ColDef>(() => {
    return {
      flex: 1,
      minWidth: 100,
    };
  }, []);
  const autoGroupColumnDef = useMemo<AutoGroupColumnDef>(() => {
    return {
      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}
            autoGroupColumnDef={autoGroupColumnDef}
            rowGroupPanelShow={"always"}
          />
        </div>
      </div>
    </AgGridProvider>
  );
};

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

[Live example: Enabling Row Group Panel](https://www.ag-grid.com/examples/grouping-group-panel/row-group-panel/reactFunctionalTs)

## Enabling the Row Group Panel

The Row Group Panel allows users to modify which columns are grouped by using drag and drop. The panel can be enabled by setting the `rowGroupPanelShow` grid option to `"always"` or `"onlyWhenGrouping"`.

Columns also need to have `enableRowGroup` set to `true` in their column definition to be dragged into the panel.

The example above enables the panel and configures the `country` and `year` columns to be controllable by the panel:

```jsx
const [columnDefs, setColumnDefs] = useState([
    { field: 'country', rowGroup: true, enableRowGroup: true },
    { field: 'year', rowGroup: true, enableRowGroup: true },
    // ...other column definitions
]);
// possible options: 'never', 'always', 'onlyWhenGrouping'
const rowGroupPanelShow = 'always';

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

## Row Group Panel in the Side Bar

The Row Group Panel is also displayed as part of the [Columns Tool Panel](https://www.ag-grid.com/react-data-grid/tool-panel-columns/) in the [Side Bar](https://www.ag-grid.com/react-data-grid/side-bar/).

#### Side Bar Row Group Panel

```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 {
  AutoGroupColumnDef,
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  GridApi,
  GridOptions,
  ModuleRegistry,
  SideBarDef,
  enableDevValidations,
} from "ag-grid-community";
import { ColumnsToolPanelModule, RowGroupingModule } from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";
import { useFetchJson } from "./useFetchJson";

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

const modules = [
  ClientSideRowModelModule,
  RowGroupingModule,
  ColumnsToolPanelModule,
];

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

  const [columnDefs, setColumnDefs] = useState<ColDef[]>([
    { field: "country", enableRowGroup: true, rowGroup: true, hide: true },
    { field: "year", enableRowGroup: true, rowGroup: true, hide: true },
    { field: "athlete", minWidth: 180 },
    { field: "total", enableValue: true, aggFunc: "sum" },
  ]);
  const defaultColDef = useMemo<ColDef>(() => {
    return {
      flex: 1,
      minWidth: 150,
    };
  }, []);
  const autoGroupColumnDef = useMemo<AutoGroupColumnDef>(() => {
    return {
      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}
            autoGroupColumnDef={autoGroupColumnDef}
            sideBar={"columns"}
          />
        </div>
      </div>
    </AgGridProvider>
  );
};

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

[Live example: Side Bar Row Group Panel](https://www.ag-grid.com/examples/grouping-group-panel/side-bar-row-group-panel/reactFunctionalTs)

The example above enabled the [Columns Tool Panel](https://www.ag-grid.com/react-data-grid/tool-panel-columns/) using the following configuration:

```jsx
const sideBar = 'columns';

<AgGridReact sideBar={sideBar} />
```

Refer to the [Side Bar](https://www.ag-grid.com/react-data-grid/side-bar/) documentation for further configuration options.

## Row Group Panel in the Toolbar

The Row Group Panel can be embedded in the [Quick Access Toolbar](https://www.ag-grid.com/react-data-grid/toolbar/#row-group-and-pivot-panels) using the `agRowGroupPanelToolbarItem` built-in item, configured independently of `rowGroupPanelShow`.

```jsx
const toolbar = {
    items: ['agRowGroupPanelToolbarItem'],
};

<AgGridReact toolbar={toolbar} />
```

## Prevent User Grouping from Hiding Columns

After a user applies row grouping to a column, the column is hidden. If the user removes the row grouping, the column is made visible again.

This behaviour can be configured by setting the `suppressGroupChangesColumnVisibility` grid option property to `true`, `"suppressHideOnGroup"` or `"suppressShowOnUngroup"`.

#### Keep Columns Visible

```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 "./styles.css";
import {
  AutoGroupColumnDef,
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  GridApi,
  GridOptions,
  ModuleRegistry,
  enableDevValidations,
} from "ag-grid-community";
import { RowGroupingModule, RowGroupingPanelModule } from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";
import { useFetchJson } from "./useFetchJson";

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

const modules = [
  ClientSideRowModelModule,
  RowGroupingModule,
  RowGroupingPanelModule,
];

const GridExample = () => {
  const gridRef = useRef<AgGridReact<IOlympicData>>(null);
  const containerStyle = useMemo(() => ({ width: "100%", height: "100%" }), []);
  const gridStyle = useMemo(() => ({ height: "100%", width: "100%" }), []);

  const [columnDefs, setColumnDefs] = useState<ColDef[]>([
    { field: "country", enableRowGroup: true },
    { field: "year", enableRowGroup: true },
    { field: "athlete", minWidth: 180 },
    { field: "total" },
  ]);
  const defaultColDef = useMemo<ColDef>(() => {
    return {
      flex: 1,
      minWidth: 150,
    };
  }, []);
  const autoGroupColumnDef = useMemo<AutoGroupColumnDef>(() => {
    return {
      minWidth: 200,
    };
  }, []);

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

  const onPropertyChange = useCallback(() => {
    const prop = (
      document.querySelector("#visibility-behaviour") as HTMLSelectElement
    ).value;
    if (prop === "true" || prop === "false") {
      gridRef.current!.api.setGridOption(
        "suppressGroupChangesColumnVisibility",
        prop === "true",
      );
    } else {
      gridRef.current!.api.setGridOption(
        "suppressGroupChangesColumnVisibility",
        prop as "suppressHideOnGroup" | "suppressShowOnUngroup",
      );
    }
  }, []);

  const resetCols = useCallback(() => {
    gridRef.current!.api.setGridOption("columnDefs", [
      { field: "country", enableRowGroup: true, hide: false },
      { field: "year", enableRowGroup: true, hide: false },
      { field: "athlete", minWidth: 180, hide: false },
      { field: "total", hide: false },
    ]);
  }, []);

  return (
    <AgGridProvider modules={modules}>
      <div style={containerStyle}>
        <div className="example-wrapper">
          <div className="example-header">
            <label>
              <span>suppressGroupChangesColumnVisibility:</span>
              <select id="visibility-behaviour" onChange={onPropertyChange}>
                <option value="false">false</option>
                <option value="true">true</option>
                <option value="suppressHideOnGroup">
                  "suppressHideOnGroup"
                </option>
                <option value="suppressShowOnUngroup">
                  "suppressShowOnUngroup"
                </option>
              </select>
            </label>
            <button onClick={resetCols}>Reset Column Visibility</button>
          </div>

          <div style={gridStyle}>
            <AgGridReact<IOlympicData>
              ref={gridRef}
              rowData={data}
              loading={loading}
              columnDefs={columnDefs}
              defaultColDef={defaultColDef}
              autoGroupColumnDef={autoGroupColumnDef}
              suppressDragLeaveHidesColumns={true}
              rowGroupPanelShow={"always"}
            />
          </div>
        </div>
      </div>
    </AgGridProvider>
  );
};

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

[Live example: Keep Columns Visible](https://www.ag-grid.com/examples/grouping-group-panel/keep-columns-visible/reactFunctionalTs)

> **Note**
>
> When dragging a column over the row group panel, the column is considered outside of the grid and so will be hidden. This behaviour can be prevented by setting `suppressDragLeaveHidesColumns` to `true`.

The following configuration can be used to prevent the column visibility from being impacted when a user changes the row group columns:

```jsx
const suppressGroupChangesColumnVisibility = true;
// prevent columns from being hidden when dragged over the row group panel
const suppressDragLeaveHidesColumns = true;

<AgGridReact
    suppressGroupChangesColumnVisibility={suppressGroupChangesColumnVisibility}
    suppressDragLeaveHidesColumns={suppressDragLeaveHidesColumns}
/>
```

## Prevent Sorting

The panel displays sort indicators, and the column pills can be clicked to change their sort. This behaviour can be prevented by setting the `rowGroupPanelSuppressSort` property to `true`.

#### Prevent Panel Sorting

```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 "./styles.css";
import {
  AutoGroupColumnDef,
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  GridApi,
  GridOptions,
  ModuleRegistry,
  enableDevValidations,
} from "ag-grid-community";
import { RowGroupingModule, RowGroupingPanelModule } from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";
import { useFetchJson } from "./useFetchJson";

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

const modules = [
  ClientSideRowModelModule,
  RowGroupingModule,
  RowGroupingPanelModule,
];

const GridExample = () => {
  const gridRef = useRef<AgGridReact<IOlympicData>>(null);
  const containerStyle = useMemo(() => ({ width: "100%", height: "100%" }), []);
  const gridStyle = useMemo(() => ({ height: "100%", width: "100%" }), []);

  const [columnDefs, setColumnDefs] = useState<ColDef[]>([
    { field: "country", enableRowGroup: true, rowGroup: true, hide: true },
    { field: "year", enableRowGroup: true, rowGroup: true, hide: true },
    { field: "athlete", minWidth: 180 },
    { field: "total" },
  ]);
  const defaultColDef = useMemo<ColDef>(() => {
    return {
      flex: 1,
      minWidth: 150,
    };
  }, []);
  const autoGroupColumnDef = useMemo<AutoGroupColumnDef>(() => {
    return {
      sort: "asc",
      minWidth: 200,
    };
  }, []);

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

  const toggle = useCallback(() => {
    const checked = document.querySelector<HTMLInputElement>(
      "#rowGroupPanelSuppressSort",
    )!.checked;
    gridRef.current!.api.setGridOption("rowGroupPanelSuppressSort", checked);
  }, []);

  return (
    <AgGridProvider modules={modules}>
      <div style={containerStyle}>
        <div className="example-wrapper">
          <div className="example-header">
            <label>
              <span>rowGroupPanelSuppressSort:</span>
              <input
                type="checkbox"
                id="rowGroupPanelSuppressSort"
                onClick={toggle}
              />
            </label>
          </div>

          <div style={gridStyle}>
            <AgGridReact<IOlympicData>
              ref={gridRef}
              rowData={data}
              loading={loading}
              columnDefs={columnDefs}
              defaultColDef={defaultColDef}
              autoGroupColumnDef={autoGroupColumnDef}
              rowGroupPanelShow={"always"}
            />
          </div>
        </div>
      </div>
    </AgGridProvider>
  );
};

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

[Live example: Prevent Panel Sorting](https://www.ag-grid.com/examples/grouping-group-panel/prevent-panel-sorting/reactFunctionalTs)

The previous example demonstrates the following configuration for preventing the Row Group Panel from sorting columns:

```jsx
const rowGroupPanelSuppressSort = true;

<AgGridReact rowGroupPanelSuppressSort={rowGroupPanelSuppressSort} />
```

## Prevent Changes to Group Order

The panel can be used to reorder or remove row grouping from columns. To prevent this, `groupLockGroupColumns` can be set to prevent removing or reordering columns. Providing `-1` will lock all columns, or provide a number representing the number of columns to lock.

#### Prevent Group Order Changes

```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 {
  AutoGroupColumnDef,
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  GridApi,
  GridOptions,
  ModuleRegistry,
  enableDevValidations,
} from "ag-grid-community";
import { RowGroupingModule, RowGroupingPanelModule } from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";
import { useFetchJson } from "./useFetchJson";

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

const modules = [
  ClientSideRowModelModule,
  RowGroupingModule,
  RowGroupingPanelModule,
];

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

  const [columnDefs, setColumnDefs] = useState<ColDef[]>([
    { field: "country", rowGroup: true, hide: true },
    { field: "year", rowGroup: true, hide: true },
    { field: "athlete", minWidth: 180 },
    { field: "total" },
  ]);
  const defaultColDef = useMemo<ColDef>(() => {
    return {
      flex: 1,
      minWidth: 150,
    };
  }, []);
  const autoGroupColumnDef = useMemo<AutoGroupColumnDef>(() => {
    return {
      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}
            autoGroupColumnDef={autoGroupColumnDef}
            rowGroupPanelShow={"always"}
            groupLockGroupColumns={-1}
          />
        </div>
      </div>
    </AgGridProvider>
  );
};

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

[Live example: Prevent Group Order Changes](https://www.ag-grid.com/examples/grouping-group-panel/prevent-group-order-changes/reactFunctionalTs)

The example above demonstrates locking the columns from their grouping being moved or removed:

```jsx
const groupLockGroupColumns = -1;

<AgGridReact groupLockGroupColumns={groupLockGroupColumns} />
```
