---
title: "Row Grouping - Group Rows"
enterprise: true
framework: javascript
version: "36.1.0"
---

# Row Grouping - Group Rows

Full width group rows can be used to represent the group structure in the grid.

#### Enabling Group Rows

```ts
import {
  ClientSideRowModelModule,
  GridApi,
  GridOptions,
  ICellRendererParams,
  ModuleRegistry,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import { RowGroupingModule } from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";

// Enable extended validations only for development
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([ClientSideRowModelModule, RowGroupingModule]);

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  columnDefs: [
    { field: "country", rowGroup: true, hide: true },
    { field: "year", rowGroup: true, hide: true },
    { field: "athlete" },
    { field: "sport" },
    { field: "total" },
  ],
  defaultColDef: {
    flex: 1,
    minWidth: 100,
  },
  groupDisplayType: "groupRows",
};

const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/olympic-winners.json")
  .then((response) => response.json())
  .then(function (data) {
    gridApi!.setGridOption("rowData", data);
  });
```

[Live example: Enabling Group Rows](https://www.ag-grid.com/examples/grouping-group-rows/enabling-group-rows/typescript)

## Enabling Group Rows

The example above demonstrates that both `country` and `year` are grouped. No group column is generated, instead using full width rows to display the group value cells.

Group Rows can be enabled by setting the `groupDisplayType` grid option to `"groupRows"` as shown below:

```js
const gridOptions = {
    groupDisplayType: 'groupRows',

    // other grid options ...
}
```

## Cell Component

The group rows use the `agGroupCellRenderer` component to display the group information, as well as the chevron control for expanding and collapsing rows.

This can be configured with several [Group Renderer Properties](https://www.ag-grid.com/javascript-data-grid/grouping-group-rows/#configurable-options) using the `groupRowRendererParams` grid option.

The example below removes the row count. Checkboxes are enabled for row selection with the `checkboxLocation` property, and `groupSelects` is set to `'descendants'` so that selecting a group row also selects all of its children.

#### Group Cell Renderer Configuration

```ts
import {
  ClientSideRowModelModule,
  GridApi,
  GridOptions,
  ModuleRegistry,
  RowSelectionModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import { RowGroupingModule } from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";

// Enable extended validations only for development
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([
  RowSelectionModule,
  ClientSideRowModelModule,
  RowGroupingModule,
]);

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  columnDefs: [
    { field: "country", rowGroup: true },
    { field: "athlete" },
    { field: "year" },
    { field: "sport" },
  ],
  defaultColDef: {
    flex: 1,
    minWidth: 100,
  },
  groupRowRendererParams: {
    suppressCount: true,
  },
  rowSelection: {
    mode: "multiRow",
    groupSelects: "descendants",
    checkboxLocation: "autoGroupColumn",
  },
  groupDisplayType: "groupRows",
};

var gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => gridApi!.setGridOption("rowData", data));
```

[Live example: Group Cell Renderer Configuration](https://www.ag-grid.com/examples/grouping-group-rows/renderer-config-group-cell/typescript)

The example above demonstrates the following configuration:

```js
const gridOptions = {
    columnDefs: [
        { field: 'total', rowGroup: true, cellRenderer: CustomMedalCellRenderer },
        // ... other column definitions
    ],
    groupRowRendererParams: {
        suppressCount: true,
    },
    rowSelection: {
        mode: 'multiRow',
        groupSelects: 'descendants',
        checkboxLocation: 'autoGroupColumn',
    },

    // other grid options ...
}
```

### Configurable Options

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `suppressPadding` | `boolean` |  |  | Set to `true` to not include any padding (indentation) in the child rows. |
| `suppressDoubleClickExpand` | `boolean` |  |  | Set to `true` to suppress expand on double click. |
| `suppressEnterExpand` | `boolean` |  |  | Set to `true` to suppress expand on ↵ Enter |
| `totalValueGetter` | `string \| TotalValueGetterFunc` |  |  | The value getter for the total row text. Can be a function or expression. |
| `suppressCount` | `boolean` |  |  | If `true`, count is not displayed beside the name. |
| `innerRenderer` | `any` |  |  | The renderer to use for inside the cell (after grouping functions are added) |
| `innerRendererParams` | `any` |  |  | Additional params to customise to the `innerRenderer`. |
| `innerRendererSelector` | `CellRendererSelectorFunc` |  |  | Callback to enable different innerRenderers to be used based of value of params. |

### Checkbox Selection

The `agGroupCellRenderer` can be configured to show checkboxes for row selection. Setting the [Row Selection](https://www.ag-grid.com/javascript-data-grid/row-selection/) `checkboxLocation` property to `'autoGroupColumn'` does not hide the [Checkbox Column](https://www.ag-grid.com/javascript-data-grid/row-selection-single-row/#customising-the-checkbox-column) but does prevent any columns configured with `agGroupCellRenderer` from showing checkboxes.

Setting `groupSelects` to `'descendants'` causes selecting a group row to also select all of its children.

#### Group Cell Renderer Checkbox Selection

```ts
import {
  ClientSideRowModelModule,
  GridApi,
  GridOptions,
  ModuleRegistry,
  RowSelectionModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import { RowGroupingModule } from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";

// Enable extended validations only for development
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([
  RowSelectionModule,
  ClientSideRowModelModule,
  RowGroupingModule,
]);

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  columnDefs: [
    { field: "country", rowGroup: true },
    { field: "athlete" },
    { field: "year" },
    { field: "sport" },
  ],
  defaultColDef: {
    flex: 1,
    minWidth: 100,
  },
  groupDisplayType: "groupRows",
  rowSelection: {
    mode: "multiRow",
    groupSelects: "descendants",
    selectAll: "all",
    checkboxLocation: "autoGroupColumn",
  },
};

var gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => gridApi!.setGridOption("rowData", data));
```

[Live example: Group Cell Renderer Checkbox Selection](https://www.ag-grid.com/examples/grouping-group-rows/renderer-config-checkbox/typescript)

The example above demonstrates the following configuration:

```js
const gridOptions = {
    rowSelection: {
        mode: 'multiRow',
        groupSelects: 'descendants',
        selectAll: 'all',
        checkboxLocation: 'autoGroupColumn',
    },

    // other grid options ...
}
```

### Custom Inner Renderer

When using the group cell renderer, the `agGroupCellRenderer` component will inherit the grouped columns renderer and display this inside of the group cell, adjacent to any configured checkboxes, cell count, and the expand/collapse chevron control.

This inner renderer can be overridden with a [Custom Cell Component](https://www.ag-grid.com/javascript-data-grid/component-cell-renderer/) by setting the `innerRenderer` and `innerRendererParams` properties on the `groupRowRendererParams` grid option.

#### Group Cell Renderer Configuration

```ts
import {
  ClientSideRowModelModule,
  GridApi,
  GridOptions,
  ModuleRegistry,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import { RowGroupingModule } from "ag-grid-enterprise";
import { CustomMedalCellRenderer } from "./customMedalCellRenderer";
import { IOlympicData } from "./interfaces";

// Enable extended validations only for development
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([ClientSideRowModelModule, RowGroupingModule]);

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  columnDefs: [
    { field: "athlete" },
    { field: "year" },
    { field: "sport" },
    { field: "total", rowGroup: true },
  ],
  defaultColDef: {
    flex: 1,
    minWidth: 100,
  },
  groupRowRendererParams: {
    suppressCount: true,
    innerRenderer: CustomMedalCellRenderer,
  },
  groupDisplayType: "groupRows",
};

var gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => gridApi!.setGridOption("rowData", data));
```

[Live example: Group Cell Renderer Configuration](https://www.ag-grid.com/examples/grouping-group-rows/renderer-config-inner/typescript)

The example above uses the following configuration to provide a custom inner renderer to the group column:

```js
const gridOptions = {
    autoGroupColumnDef: {
        cellRendererParams: {
            innerRenderer: CustomMedalCellRenderer,
        },
    },

    // other grid options ...
}
```

### Custom Cell Renderer

The Group Cell Renderer can be entirely replaced with a [Custom Cell Component](https://www.ag-grid.com/javascript-data-grid/component-cell-renderer/) by setting the `groupRowRenderer` grid option.

#### Custom Group Cell Renderer

```ts
import {
  CellDoubleClickedEvent,
  CellKeyDownEvent,
  ClientSideRowModelModule,
  ColDef,
  GridApi,
  GridOptions,
  ModuleRegistry,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import { RowGroupingModule } from "ag-grid-enterprise";
import { CustomGroupCellRenderer } from "./customGroupCellRenderer";
import { IOlympicData } from "./interfaces";

// Enable extended validations only for development
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([ClientSideRowModelModule, RowGroupingModule]);

const columnDefs: ColDef[] = [
  {
    field: "country",
    hide: true,
    rowGroup: true,
  },
  {
    field: "year",
    hide: true,
    rowGroup: true,
  },
  {
    field: "athlete",
  },
  {
    field: "sport",
  },
  {
    field: "total",
    aggFunc: "sum",
  },
];

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  columnDefs: columnDefs,
  groupRowRenderer: CustomGroupCellRenderer,
  defaultColDef: {
    flex: 1,
    minWidth: 120,
  },
  onCellDoubleClicked: (params: CellDoubleClickedEvent<IOlympicData, any>) => {
    if (params.colDef.showRowGroup) {
      params.node.setExpanded(!params.node.expanded);
    }
  },
  onCellKeyDown: (params: CellKeyDownEvent<IOlympicData, any>) => {
    if (!("colDef" in params)) {
      return;
    }
    if (!(params.event instanceof KeyboardEvent)) {
      return;
    }
    if (params.event.code !== "Enter") {
      return;
    }
    if (params.colDef.showRowGroup) {
      params.node.setExpanded(!params.node.expanded);
    }
  },
  groupDisplayType: "groupRows",
};

const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/small-olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => gridApi!.setGridOption("rowData", data));
```

[Live example: Custom Group Cell Renderer](https://www.ag-grid.com/examples/grouping-group-rows/renderer-config-custom/typescript)

The example above sets a custom cell renderer using the following configuration:

```js
const gridOptions = {
    groupRowRenderer: CustomGroupCellRenderer,

    // other grid options ...
}
```
