# Row Grouping

Canonical page: https://www.adaptabletools.com/docs/handbook-grouping-rows

- AdapTable fully supports AG Grid Row Grouping and additionally provides a few related features
- Row Groups can be defined in Layouts and currently expanded Row Groups can be persisted

AG Grid makes it very easy for you to group your data through [Row Grouping](https://www.ag-grid.com/javascript-data-grid/grouping/).

AdapTable adds a number helpful features and options to improve the Row Grouping experience.

Row Groups in AdapTable are defined (and saved) in [Layouts](https://www.adaptabletools.com/docs/handbook-layouts/index.md) (both Table and Pivot)

- For [Table Layouts](https://www.adaptabletools.com/docs/handbook-layouts-table/index.md) use the `RowGroupedColumns` property
- For [Pivot Layouts](https://www.adaptabletools.com/docs/handbook-layouts-pivot/index.md) use the `PivotGroupedColumns` property

**Example: Row Grouping: Basics**

Configuring Row Groups in AdapTable

 

- This Demo creates a Layout with Row Grouping (entitled `Grouped Layout`) which it sets as the Current Layout.  It has the following features:
  - **2 Row Grouping Columns**: `language` and `license`
  - **2 (SUM) Aggregations**: AG Grid calculates & displays each Column value for `Github Watchers` & `Github Stars` in the Grouped Row
- We use the AG Grid api to open the 'Columns' [Tool Panel](https://www.adaptabletools.com/docs/ui-tool-panel/index.md) so its easier to see what has been set

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts
  index.ts             [template]
  onAdaptableReady.ts
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Row Grouping: Basic',
  initialState: {
    Dashboard: {
      Tabs: [{Name: 'Demo', Toolbars: ['Layout']}],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Layout'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Grouped Layout',
      Layouts: [
        {
          Name: 'Grouped Layout',
          RowGroupedColumns: ['language', 'license'],
          TableAggregationColumns: [
            {
              ColumnId: 'github_watchers',
              AggFunc: 'sum',
            },
            {
              ColumnId: 'github_stars',
              AggFunc: 'sum',
            },
          ],
          SuppressAggFuncInHeader: true,
          TableColumns: [
            'name',
            'github_stars',
            'language',
            'github_watchers',
            'updated_at',
            'license',
            'description',
            'created_at',
          ],
          AutoSizeColumns: true,
        },
        {
          TableColumns: [
            'name',
            'github_stars',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'github_watchers',
            'description',
            'open_issues_count',
            'closed_issues_count',
            'open_pr_count',
            'closed_pr_count',
            'has_projects',
            'has_pages',
            'week_issue_change',
          ],
          Name: 'Single Grouping Layout',
          RowGroupedColumns: ['language', 'license'],
          RowGroupDisplayType: 'single',
          RowGroupValues: {
            RowGroupDefaultBehavior: 'always-expanded',
          },
          AutoSizeColumns: true,
        },
        {
          TableColumns: [
            'name',
            'github_stars',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'github_watchers',
            'description',
            'open_issues_count',
            'closed_issues_count',
            'open_pr_count',
            'closed_pr_count',
            'has_projects',
            'has_pages',
            'week_issue_change',
          ],
          Name: 'Multi Grouping Layout',
          RowGroupedColumns: ['language', 'license'],
          RowGroupDisplayType: 'multi',
          RowGroupValues: {
            RowGroupDefaultBehavior: 'always-expanded',
          },
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```
**`src/gridOptions.ts`**

```ts
import {GridOptions, themeBalham} from 'ag-grid-enterprise';

import {rowData} from './rowData';
import {columnDefs} from './columnDefs';

export const gridOptions: GridOptions = {
  theme: themeBalham,
  defaultColDef: {
    resizable: true,
    sortable: true,
    editable: true,
    filter: true,
    floatingFilter: true,
  },
  columnDefs: columnDefs,
  rowData: rowData,
  sideBar: true,
  suppressMenuHide: true,
  cellSelection: true,
  rowGroupPanelShow: 'always',

  statusBar: {
    statusPanels: [
      {statusPanel: 'agTotalRowCountComponent', align: 'left'},
      {statusPanel: 'agFilteredRowCountComponent'},
      {
        key: 'Center Panel',
        statusPanel: 'AdaptableStatusPanel',
        align: 'center',
      },
    ],
  },
};
```
**`src/onAdaptableReady.ts`**

```ts
import {AdaptableReadyInfo} from '@adaptabletools/adaptable';

export const onAdaptableReady = ({agGridApi}: AdaptableReadyInfo) => {
  agGridApi.openToolPanel('columns');
};
```

# Defining Row Groups

Row Groups can be defined in both Table Layouts and Pivot Layouts

### Defining a Table Layout with Row Grouping

The `RowGroupedColumns` property is an array of (string) ColumnId

This defines the **order** in which Columns will be row-grouped.

The Rows in the Group will be sorted using the Column's default sort order (including Custom Sorts if they have been provided).

By default Row Grouped Columns are always placed at the left of the Grid but the Layout definition can [position them anywhere](https://www.adaptabletools.com/docs/handbook-grouping-rows/index.md#positioning-row-groups)

By default all Row Grouped Columns appear in one Column (named "Group").

Use `RowGroupDisplayType` property to change this to 'multi' (default is 'single')

The Layout can be configured so that all, none or a defined list of Row Groups are expanded / collapsed when it opens.

See [Row Groups Expanded / Collapsed Behaviour](https://www.adaptabletools.com/docs/handbook-grouping-rows-expanded-collapsed/index.md) for full details

```ts [[1, 12, "RowGroupedColumns"], [2, 13, "RowGroupDisplayType"], [3, 14, "RowGroupValues"]]
// Define a Grouping and Aggregation Layout called "Grouping Layout" as follows:
// AG Grid Row Grouping on 2 Columns: 'license' and 'language'
// RowGroupDisplayType is multi (so each Row Group has own column)
// Row Groups to be collapsed when Layout loads (with 4 exceptions listed)
const initialState: InitialState = {
  Layout: {
    CurrentLayout: 'Grouping Layout',
    Layouts: [
    {
      Name: 'Grouping Layout',
      TableColumns: ['github_stars', 'open_pr_count', 'github_watchers', 'examResult', 'attendance'],
      RowGroupedColumns: ['license', 'language'],
      RowGroupDisplayType: 'multi',
      RowGroupValues: {
          RowGroupDefaultBehavior: 'collapsed',
          GroupKeys: [
          {
            RowGroupedColumns: ['language', 'license'],
            ExceptionGroupKeys: [
              ['TypeScript'],
              ['TypeScript', 'MIT License'],
              ['JavaScript'],
              ['JavaScript', 'Other'],
            ],
          },
          ],
      },
    }],
  },
}
```

### Defining a Pivot Layout with Row Grouping

The `PivotGroupedColumns` property is an array of (string) ColumnId

This defines the **order** in which Columns will be row-grouped.

The Rows in the Group will be sorted using the Column's default sort order (including Custom Sorts if they have been provided).

By default Row Grouped Columns are always placed at the left of the Grid but the Layout definition can [position them anywhere](https://www.adaptabletools.com/docs/handbook-grouping-rows/index.md#positioning-row-groups)

By default all Row Grouped Columns appear in one Column (named "Group").

Use `RowGroupDisplayType` property to change this to 'multi' (default is 'single')

The Layout can be configured so that all, none or a defined list of Row Groups are expanded / collapsed when it opens.

See [Row Groups Expanded / Collapsed Behaviour](https://www.adaptabletools.com/docs/handbook-grouping-rows-expanded-collapsed/index.md) for full details

```ts [[1, 12, "PivotGroupedColumns"], [2, 13, "RowGroupDisplayType"], [3, 14, "RowGroupValues"]]
// Define a Pivot Layout called "Grouping Layout" as follows:
// AG Grid Row Grouping on 2 Columns: 'country' and 'counterparty'
// RowGroupDisplayType is multi (so each Row Group has own column)
// Row Groups to be expanded when Layout loads
const initialState: InitialState = {
  Layout: {
    CurrentLayout: 'Grouping Layout',
    Layouts: [
    {
      Name: 'Grouping Layout',
      PivotColumns: ['currency'],
      PivotGroupedColumns: ['country', 'counterparty'],
      RowGroupDisplayType: 'multi',
      RowGroupValues: {
          RowGroupDefaultBehavior: 'always-expanded',
      },
    }],
  },
}
```

## Multiple Row Group Columns

AG Grid can been configured to show each Row Group in a **separate** column.

This is supported by AdapTable by the `RowGroupDisplayType` property in each [Layout](https://www.adaptabletools.com/docs/handbook-layouts/index.md).

- AdapTable **ignores** AG Grid's `groupDisplayType` property if the `RowGroupDisplayType` property is set
- i.e. if `RowGroupDisplayType` is *multi*, multiple row group cols are displayed, even if AG Grid is set to 'singleColumn'

When this property is set to `multi`, AdapTable will:
- display each Row Group in its own Column
- use the Column's Friendly Name as the Header (instead of "Group")

See below for instructions on positioning and pinning Row Group Columns when `RowGroupDisplayType` is *multi*

- There is another option for this value, `groupRows`, which sets the Grouped Row to be full width
- See [Grouped Rows](https://www.adaptabletools.com/docs/handbook-grouping-rows-grouped-rows/index.md) for full details

**Example: Row Grouping: Multiple Columns**

Displaying each Row Group in its own Column

 

- This demo shows the options for Multi Row Grouping.  We have  via x Layouts (that both group by Language and License):
  - `MultiCol Grouped` - each Row Group has its own Column
  - `SingleCol Grouped` - both Row Groups are in the same Column

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Row Grouping: Multiple Columns',
  initialState: {
    Dashboard: {
      Tabs: [{Name: 'Demo', Toolbars: ['Layout']}],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Layout'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Multi Col Table',
      Layouts: [
        {
          Name: 'Multi Col Table',
          RowGroupDisplayType: 'multi',
          RowGroupValues: {
            RowGroupDefaultBehavior: 'always-expanded',
          },
          RowGroupedColumns: ['language', 'license'],
          TableAggregationColumns: [
            {
              ColumnId: 'github_watchers',
              AggFunc: 'sum',
            },
            {
              ColumnId: 'github_stars',
              AggFunc: 'sum',
            },
          ],
          SuppressAggFuncInHeader: true,
          TableColumns: [
            'name',
            'github_stars',
            'github_watchers',
            'updated_at',
            'description',
            'created_at',
          ],
          AutoSizeColumns: true,
        },
        {
          Name: 'Single Col Table',
          RowGroupDisplayType: 'single', //the default
          RowGroupValues: {
            RowGroupDefaultBehavior: 'always-expanded',
          },
          RowGroupedColumns: ['language', 'license'],
          TableAggregationColumns: [
            {
              ColumnId: 'github_watchers',
              AggFunc: 'sum',
            },
            {
              ColumnId: 'github_stars',
              AggFunc: 'sum',
            },
          ],
          SuppressAggFuncInHeader: true,
          TableColumns: [
            'name',
            'github_stars',
            'github_watchers',
            'updated_at',
            'description',
            'created_at',
          ],
          AutoSizeColumns: true,
        },
        {
          Name: 'Multi Col Pivot',
          RowGroupDisplayType: 'multi',
          RowGroupValues: {
            RowGroupDefaultBehavior: 'always-expanded',
          },
          PivotGroupedColumns: ['language', 'license'],
          PivotAggregationColumns: [
            {
              ColumnId: 'github_watchers',
              AggFunc: 'sum',
            },
            {
              ColumnId: 'github_stars',
              AggFunc: 'sum',
            },
          ],
          SuppressAggFuncInHeader: true,
          PivotColumns: ['has_wiki'],
          AutoSizeColumns: true,
        },
        {
          Name: 'Single Col Pivot',
          RowGroupDisplayType: 'single', //the default
          RowGroupValues: {
            RowGroupDefaultBehavior: 'always-expanded',
          },
          PivotGroupedColumns: ['language', 'license'],
          PivotAggregationColumns: [
            {
              ColumnId: 'github_watchers',
              AggFunc: 'sum',
            },
            {
              ColumnId: 'github_stars',
              AggFunc: 'sum',
            },
          ],
          SuppressAggFuncInHeader: true,
          PivotColumns: ['has_wiki'],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```
**`src/gridOptions.ts`**

```ts
import {GridOptions, themeBalham} from 'ag-grid-enterprise';

import {rowData} from './rowData';
import {columnDefs} from './columnDefs';

export const gridOptions: GridOptions = {
  theme: themeBalham,
  defaultColDef: {
    resizable: true,
    sortable: true,
    editable: true,
    filter: true,
    floatingFilter: true,
  },
  columnDefs: columnDefs,
  rowData: rowData,
  sideBar: true,
  suppressMenuHide: true,
  cellSelection: true,
  rowGroupPanelShow: 'always',
  groupDisplayType: 'singleColumn',
  statusBar: {
    statusPanels: [
      {statusPanel: 'agTotalRowCountComponent', align: 'left'},
      {statusPanel: 'agFilteredRowCountComponent'},
      {
        key: 'Center Panel',
        statusPanel: 'AdaptableStatusPanel',
        align: 'center',
      },
    ],
  },
};
```

## Expanded / Collapsed Row Groups

Developers can configure, when a Layout loads, what is the collapsed or expanded behaviour for Row Groups.

They can also provide exceptions, and save the currently expanded (or collapsed) Row Groups to State.

See [Row Groups Expanded and Collapsed Behaviour](https://www.adaptabletools.com/docs/handbook-grouping-rows-expanded-collapsed/index.md) for full details and accompanying demos

## Managing Row Groups

Row Grouped Columns can be managed in similar ways to other columns, i.e. they can be:

- [formatted and styled](https://www.adaptabletools.com/docs/handbook-grouping-rows-formatting/index.md)
- [sorted](https://www.adaptabletools.com/docs/handbook-grouping-rows-sorting/index.md)
- [filtered](https://www.adaptabletools.com/docs/handbook-grouping-rows-filtering/index.md)

## Positioning Row Groups

Row Grouped Columns are most typically placed in the first column of the Grid to the left of all other Columns.

However AG Grid allows Row Grouped columns to be positioned anywhere in the Grid.

This is fully supported by AdapTable and it will store the columns' positions accurately in the [Layout](https://www.adaptabletools.com/docs/handbook-layouts/index.md).

Currently it is **not** possible to re-position Row Groups in the Layout Wizard - but that behaviour is coming soon

Additionally, it is possible to define a Layout in Initial State where the Row Group is not the first Column.

### Configuring Row Group Position in Layout Definitions

If you want the Row Groups to be positioned at the left of the Grid - the default behaviour - then nothing additional is required to what is described in [Defining Row Groups in Layouts](https://www.adaptabletools.com/docs/handbook-layouts-table/index.md).

However, in order to position a Row Grouped Column **not** at the left of the Grid, you need to add "ag-Grid-AutoColumn" into the `TableColumns` (array) property in the Layout Definition at the required position.

For instance to place the Row Group Column as the second Column, the Layout should look like this:

```tsx
Layouts: [
{
  Name: 'Grouped Layout',
  RowGroupedColumns: ['language', 'license'],
  TableColumns: [
    'name',
    'ag-Grid-AutoColumn',
    'github_stars',
    'github_watchers',
    'updated_at',
    'pushed_at',
    'description',
    'created_at',
  ],
}],
```

**Example: Row Grouping: Positioning Single**

Positioning Single Row Groups in AdapTable

 

- In this example we have configured Row Grouping on 2 columns:`Language` and `License` Columns
- However, we have defined the Row Group Column to be the **second** Column
- We have also added pinning to the first 2 columns (`Name` and the Row-Grouped Column)

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts
  index.ts             [template]
  onAdaptableReady.ts
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Row Grouping: Positioning Single',
  initialState: {
    Dashboard: {
      PinnedToolbars: ['Layout'],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Layout'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Grouped Layout',
      Layouts: [
        {
          Name: 'Grouped Layout',
          RowGroupedColumns: ['language', 'license'],
          ColumnPinning: {name: 'left', 'ag-Grid-AutoColumn': 'left'},
          TableColumns: [
            'name',
            'ag-Grid-AutoColumn',
            'github_stars',
            'github_watchers',
            'updated_at',
            'pushed_at',
            'description',
            'created_at',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```
**`src/gridOptions.ts`**

```ts
import {GridOptions, themeBalham} from 'ag-grid-enterprise';

import {rowData} from './rowData';
import {columnDefs} from './columnDefs';

export const gridOptions: GridOptions = {
  theme: themeBalham,
  defaultColDef: {
    resizable: true,
    sortable: true,
    editable: true,
    filter: true,
    floatingFilter: true,
  },
  columnDefs: columnDefs,
  rowData: rowData,
  sideBar: true,
  suppressMenuHide: true,
  cellSelection: true,
  rowGroupPanelShow: 'always',

  statusBar: {
    statusPanels: [
      {statusPanel: 'agTotalRowCountComponent', align: 'left'},
      {statusPanel: 'agFilteredRowCountComponent'},
      {
        key: 'Center Panel',
        statusPanel: 'AdaptableStatusPanel',
        align: 'center',
      },
    ],
  },
};
```
**`src/onAdaptableReady.ts`**

```ts
import {AdaptableReadyInfo} from '@adaptabletools/adaptable';

export const onAdaptableReady = ({agGridApi}: AdaptableReadyInfo) => {
  agGridApi.openToolPanel('columns');
};
```

### Positioning Multi Row Groups

As noted above, AdapTable supports displaying each Row Group in a **separate** column.

This includes positioning the multiple Row Group Columns so they are not displayed at the start of the Grid.

### Configuring Multiple Row Group Positions in Layout Definitions

When AG Grid is showing multiple Row Group Columns (i.e. `RowGroupDisplayType` has been set to 'multi' in the Layout), you need to list each Row Group separately.

This is achieved by adding `ag-Grid-AutoColumn-` followed by the Column Id.

For instance to group on the `language` and `license` columns you will set:

```tsx
Layouts: [
{
  Name: 'Grouped Layout',
  RowGroupedColumns: ['language', 'license'],
  TableColumns: [
    'name',
    'ag-Grid-AutoColumn-language',
    'ag-Grid-AutoColumn-license',
    'github_stars',
    'github_watchers',
    'updated_at',
    'pushed_at',
    'description',
    'created_at',
  ],
}],
```

Note: this allows you to put the Row Grouped Columns wherever you want and in any order, e.g.:

```tsx
Layouts: [
{
  Name: 'Grouped Layout',
  RowGroupedColumns: ['language', 'license'],
  TableColumns: [
    'name',
    'ag-Grid-AutoColumn-license',
    'github_stars',
    'github_watchers',
    'updated_at',
    'ag-Grid-AutoColumn-language',
    'pushed_at',
    'description',
    'created_at',
  ],
}],
```

**Example: Row Grouping: Positioning Multiple**

Positioning Multiple Row Groups in AdapTable

 

- Here we Row Group on `Language` and `License` Columns (as in demo above), but AG Grid has been set to show Multiple Row Group columns
- Accordingly we have defined AdapTable to display 2 Row Group Columns (as **second** and **third** Columns - but they can be positioned anywhere)

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts
  index.ts             [template]
  onAdaptableReady.ts
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Row Grouping: Positioning Multiple',
  initialState: {
    Dashboard: {
      PinnedToolbars: ['Layout'],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Layout'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Grouped Layout',
      Layouts: [
        {
          Name: 'Grouped Layout',
          RowGroupedColumns: ['language', 'license'],
          TableColumns: [
            'name',
            'ag-Grid-AutoColumn-language',
            'ag-Grid-AutoColumn-license',
            'github_stars',
            'github_watchers',
            'updated_at',
            'pushed_at',
            'description',
            'created_at',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```
**`src/gridOptions.ts`**

```ts
import {GridOptions, themeBalham} from 'ag-grid-enterprise';

import {rowData} from './rowData';
import {columnDefs} from './columnDefs';

export const gridOptions: GridOptions = {
  theme: themeBalham,
  defaultColDef: {
    resizable: true,
    sortable: true,
    editable: true,
    filter: true,
    floatingFilter: true,
  },
  columnDefs: columnDefs,
  rowData: rowData,
  sideBar: true,
  suppressMenuHide: true,
  cellSelection: true,
  rowGroupPanelShow: 'always',
  groupDisplayType: 'multipleColumns',
  statusBar: {
    statusPanels: [
      {statusPanel: 'agTotalRowCountComponent', align: 'left'},
      {statusPanel: 'agFilteredRowCountComponent'},
      {
        key: 'Center Panel',
        statusPanel: 'AdaptableStatusPanel',
        align: 'center',
      },
    ],
  },
};
```
**`src/onAdaptableReady.ts`**

```ts
import {AdaptableReadyInfo} from '@adaptabletools/adaptable';

export const onAdaptableReady = ({agGridApi}: AdaptableReadyInfo) => {
  agGridApi.openToolPanel('columns');
};
```

## Pinning Row Groups

Row Grouped Columns can be pinned.  

This is done by adding 'ag-Grid-AutoColumn' to the `ColumnPinning` property in the Layout definition.

**Example: Row Grouping: Pinning Single Row Group**

Pinning Single Row Grouped Columns in AdapTable

 

- This example we are grouping on the `Language` Column and we pinned it to the left

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Row Grouping: Pinning Single',
  initialState: {
    Dashboard: {
      Tabs: [{Name: 'Demo', Toolbars: ['Layout']}],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Layout'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Pinned Grouped Single Layout',
      Layouts: [
        {
          Name: 'Pinned Grouped Single Layout',
          RowGroupedColumns: ['language'],
          RowGroupValues: {
            RowGroupDefaultBehavior: 'always-expanded',
          },
          RowGroupDisplayType: 'single',
          TableAggregationColumns: [
            {
              ColumnId: 'github_watchers',
              AggFunc: 'sum',
            },
            {
              ColumnId: 'github_stars',
              AggFunc: 'sum',
            },
          ],
          ColumnPinning: {'ag-Grid-AutoColumn': 'left'},
          SuppressAggFuncInHeader: true,
          TableColumns: [
            'name',
            'github_stars',
            'github_watchers',
            'updated_at',
            'license',
            'description',
            'created_at',
            'open_pr_count',
            'closed_pr_count',
            'has_projects',
            'has_pages',
            'week_issue_change',
          ],
          AutoSizeColumns: true,
        },
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'github_stars',
            'language',
            'github_watchers',
            'updated_at',
            'description',
            'created_at',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```
**`src/gridOptions.ts`**

```ts
import {GridOptions, themeBalham} from 'ag-grid-enterprise';

import {rowData} from './rowData';
import {columnDefs} from './columnDefs';

export const gridOptions: GridOptions = {
  theme: themeBalham,
  defaultColDef: {
    resizable: true,
    sortable: true,
    editable: true,
    filter: true,
    floatingFilter: true,
  },
  columnDefs: columnDefs,
  rowData: rowData,
  sideBar: true,
  suppressMenuHide: true,
  cellSelection: true,
  rowGroupPanelShow: 'always',

  statusBar: {
    statusPanels: [
      {statusPanel: 'agTotalRowCountComponent', align: 'left'},
      {statusPanel: 'agFilteredRowCountComponent'},
      {
        key: 'Center Panel',
        statusPanel: 'AdaptableStatusPanel',
        align: 'center',
      },
    ],
  },
};
```

### Pinning Multi Row Groups

When AG Grid is showing multiple Row Group Columns (i.e. `RowGroupDisplayType` has been set to 'multi' in the Layout), you need to list each Row Group separately.

This is achieved by adding `ag-Grid-AutoColumn-` followed by the Column Id.

The same thing is required whenever you set `RowGroupDisplayType` to 'multi' - see Positioning Multi Groups above

**Example: Row Grouping: Pinning Multiple Row Groups**

Pinning Multiple Row Grouped Columns in AdapTable

 

- This example we are grouping on the `Language` Column and we pinned it to the left

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Row Grouping: Pinning Multi',
  initialState: {
    Dashboard: {
      Tabs: [{Name: 'Demo', Toolbars: ['Layout']}],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Layout'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Pinned Grouped Multi Layout',
      Layouts: [
        {
          Name: 'Pinned Grouped Multi Layout',
          RowGroupedColumns: ['language', 'license'],
          RowGroupValues: {
            RowGroupDefaultBehavior: 'always-expanded',
          },
          RowGroupDisplayType: 'multi',
          TableAggregationColumns: [
            {
              ColumnId: 'github_watchers',
              AggFunc: 'sum',
            },
            {
              ColumnId: 'github_stars',
              AggFunc: 'sum',
            },
          ],
          ColumnPinning: {
            'ag-Grid-AutoColumn-language': 'left',
            'ag-Grid-AutoColumn-license': 'left',
          },
          SuppressAggFuncInHeader: true,
          TableColumns: [
            'name',
            'github_stars',
            'github_watchers',
            'updated_at',
            'description',
            'created_at',
            'open_pr_count',
            'closed_pr_count',
            'has_projects',
            'has_pages',
            'week_issue_change',
          ],
          AutoSizeColumns: true,
        },
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'github_stars',
            'language',
            'github_watchers',
            'updated_at',
            'description',
            'created_at',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```
**`src/gridOptions.ts`**

```ts
import {GridOptions, themeBalham} from 'ag-grid-enterprise';

import {rowData} from './rowData';
import {columnDefs} from './columnDefs';

export const gridOptions: GridOptions = {
  theme: themeBalham,
  defaultColDef: {
    resizable: true,
    sortable: true,
    editable: true,
    filter: true,
    floatingFilter: true,
  },
  columnDefs: columnDefs,
  rowData: rowData,
  sideBar: true,
  suppressMenuHide: true,
  cellSelection: true,
  rowGroupPanelShow: 'always',

  statusBar: {
    statusPanels: [
      {statusPanel: 'agTotalRowCountComponent', align: 'left'},
      {statusPanel: 'agFilteredRowCountComponent'},
      {
        key: 'Center Panel',
        statusPanel: 'AdaptableStatusPanel',
        align: 'center',
      },
    ],
  },
};
```

## Sizing Row Groups

Row Grouped Columns can be given custom widths.  

This is done by adding 'ag-Grid-AutoColumn' to the `ColumnSizing` property in the Layout definition.

**Example: Row Grouping: Sizing Row Group Column**

Sizing Row Grouped Columns in AdapTable

 

- This example we are grouping on the `License` Column and we gave it a width of 350px

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Row Grouping: Width',
  initialState: {
    Dashboard: {
      Tabs: [
        {
          Name: 'Default',
          Toolbars: ['Layout'],
        },
      ],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Layout'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Row Grouping Widths Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'topics',
            'open_pr_count',
            'closed_pr_count',
          ],
          RowGroupedColumns: ['license'],
          ColumnSizing: {'ag-Grid-AutoColumn': {Width: 350}},
          Name: 'Row Grouping Widths Layout',
        },
      ],
    },
  },
};
```
**`src/gridOptions.ts`**

```ts
import {GridOptions, themeBalham} from 'ag-grid-enterprise';

import {rowData} from './rowData';
import {columnDefs} from './columnDefs';

export const gridOptions: GridOptions = {
  theme: themeBalham,
  defaultColDef: {
    resizable: true,
    sortable: true,
    editable: true,
    filter: true,
    floatingFilter: true,
  },
  columnDefs: columnDefs,
  rowData: rowData,
  sideBar: true,
  suppressMenuHide: true,
  cellSelection: true,
  rowGroupPanelShow: 'always',

  statusBar: {
    statusPanels: [
      {statusPanel: 'agTotalRowCountComponent', align: 'left'},
      {statusPanel: 'agFilteredRowCountComponent'},
      {
        key: 'Center Panel',
        statusPanel: 'AdaptableStatusPanel',
        align: 'center',
      },
    ],
  },
};
```
