# Configuring Column Header

Canonical page: https://www.adaptabletools.com/docs/dev-guide-columns-column-headers

- AdapTable users are able to change the Header / Caption of a Column in AG Grid in 2 ways:
  - Changes configured in a particular Layout
  - Changes set through the `columnHeader` function in Column Options

By default, AdapTable will show as the header (or caption) of the Column (ie. the text that appears in the Header Bar) the default value provided in AG Grid's ColumnDefs.

However this can be changed in AdapTable in 2 ways:
- on a [per-Layout](https://www.adaptabletools.com/docs/handbook-layouts/index.md) basis using the `ColumnHeaders` property
- via the `columnHeader` function in [Column Options](https://www.adaptabletools.com/docs/technical-reference-column/index.md)

When both are used, the function is **always called**. The Layout caption is passed into the function so you can honour a user override, keep the AG Grid header, or apply your own value.

- This page is the source for the text that appears in the Grid header
- To change how the Column is labelled in the AdapTable UI (Settings Panel, Expression Editor, and so on), use `columnFriendlyName` — see [Adaptable Column](https://www.adaptabletools.com/docs/dev-guide-columns-adaptable-column/index.md)

## Per Layout

A given [Layout](https://www.adaptabletools.com/docs/handbook-layouts/index.md) can store a caption for a Column using the `ColumnHeaders` property.

- This enables the same Column to have different Headers / Captions in 2 Layouts
- It also allows the Column's Header to be set at run-time via the AdapTable UI

A custom Column Header can be set in a Layout (using the `ColumnHeaders` property) in many ways:

- In [Layout Initial State](https://www.adaptabletools.com/docs/handbook-layouts-table-column-headers/index.md) (i.e. by developers at design-time) 
- Using the `Change Caption` menu option in each [Column Menu](https://www.adaptabletools.com/docs/ui-column-menu/index.md)
- In the `Columns` section of the Layout Wizard (via the dropdown which opens an expanded section)
- Programmatically using the `setColumnCaption` function in [Layout API](https://www.adaptabletools.com/docs/technical-reference-layouts/index.md)

- AG Grid makes it easy to wrap Column Headers - useful when the header text is wider than the cell text
- The `wrapHeaderText` & `autoHeaderHeight` props in Column Defs, when set to *true*, creates the necessary effect

**Example: Custom Column Headers Layout**

Providing Alternative Column Headers in a Layout

- This demo shows how to change the Column Header on a per-Layout basis
- In the Initial State for the `Standard` Layout we change 'Name' to `JavaScript Framework` and 'Gihub Stars' to `Fans`
- Note: we set `wrapHeaderText` and `autoHeaderHeight` to *true* in Column Def's to create a better visual effect
- We provide a Dashboard button to allow the Header for "Updated" to be set via the [Layout API](https://www.adaptabletools.com/docs/technical-reference-layouts/index.md)

- Switch between Layouts and note that the `Grouped` Layout contains the original Column Headers
- Change a Column Header using the `Change Header` Menu Item in the [Column Menu](https://www.adaptabletools.com/docs/ui-column-menu/index.md)
- Change another Column's Header by using the Layout Editor's Wizard

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 {
  AdaptableButton,
  DashboardButtonContext,
} from '@adaptabletools/adaptable';
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'tradeId',
  userName: 'Demo User',
  adaptableId: 'Column Headers Layout',
  dashboardOptions: {
    customDashboardButtons: [
      {
        label: 'Change "Updated" Column Header',
        buttonStyle: {
          tone: 'neutral',
          variant: 'outlined',
        },
        onClick: (
          _button: AdaptableButton<DashboardButtonContext>,
          context: DashboardButtonContext
        ) => {
          context.adaptableApi.layoutApi.setColumnCaption(
            'updated_at',
            'Most Recently Changed'
          );
        },
      },
    ],
  },
  initialState: {
    Dashboard: {
      Tabs: [
        {
          Name: 'Demo',
          Toolbars: ['Layout'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'updated_at',
            'has_wiki',
            'created_at',
            'pushed_at',
            'github_watchers',
          ],
          ColumnHeaders: {
            github_stars: 'Fans',
            name: 'JavaScript Framework',
          },
          ColumnSizing: {
            name: {Width: 120},
          },
        },
        {
          Name: 'Grouped Layout',
          RowGroupedColumns: ['license'],
          TableAggregationColumns: [
            {
              ColumnId: 'github_watchers',
              AggFunc: 'sum',
            },
            {
              ColumnId: 'github_stars',
              AggFunc: 'sum',
            },
          ],
          SuppressAggFuncInHeader: true,
          TableColumns: [
            'name',
            'github_stars',
            'language',
            'github_watchers',
            'updated_at',
          ],
        },
      ],
    },
  },
};
```

**`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: {
    sortable: true,
    filter: true,
    floatingFilter: true,
    enableRowGroup: true,
    wrapHeaderText: true,
    autoHeaderHeight: true,
  },
  columnDefs: columnDefs,
  rowData: rowData,
  sideBar: true,
};
```

## Using a Function

The `columnHeader` function in [Column Options](https://www.adaptabletools.com/docs/technical-reference-column/index.md) provides a more configurable way to change Column Headers.

The function is **always invoked** (if provided)

This includes when the current Layout already has a caption for that Column

That lets you choose, per column, between 3 values:

(1) `colDefHeaderName`: the original AG Grid Column Definition header
(2) a value you compute in the function
(3) `layoutSpecificHeaderName`: a caption the user (or Initial State) set on the Layout

The typical pattern is: use (2) unless the user has changed the header themselves, in which case use (3).

```ts [[3, 4, "layoutSpecificHeaderName"], [2, 8, "JS Framework"], [1, 11, "colDefHeaderName"]]
columnHeader: (context) => {
  // 3: the user overrode the header in the Layout — honour that
  if (context.layoutSpecificHeaderName) {
    return context.layoutSpecificHeaderName;
  }
  // 2: developer override for the Name column
  if (context.columnType === 'tableColumn' && context.columnId === 'name') {
    return 'JS Framework';
  }
  // 1: fall back to the AG Grid header
  return context.colDefHeaderName;
}
```

- `defaultHeaderName` is the resolved value that would be displayed if no function were provided
- This is the Layout caption if one exists, otherwise the ColDef header

The function's context supports many different categories of column, including dynamically created ones.

### `columnHeader`

Provide Custom Column Headers

This function allows developers to provide custom Headers for any Column in AG Grid.

It receives a [`ColumnHeaderContext`](https://www.adaptabletools.com/docs/reference/columnheadercontext.md) object and returns a string.

Every context object includes the Layout / ColDef header properties listed below, plus extra fields that change based on the type of the Column.

There are 9 different types of Column supported.

<b>Base Context</b>

All context objects derive from [`BaseColumnHeaderContext`](https://www.adaptabletools.com/docs/reference/basecolumnheadercontext.md) which is defined as follows:

| Property | Type | Description |
| --- | --- | --- |
| [colDefHeaderName](https://www.adaptabletools.com/docs/reference/basecolumnheadercontext.md#coldefheadername) | `string` | Original header name from the Column Definition (`headerName`, or a humanised `field` when `headerName` is not set).<br/>Never affected by Layout-specific headers. |
| [currentLayout](https://www.adaptabletools.com/docs/reference/basecolumnheadercontext.md#currentlayout) | [`Layout`](https://www.adaptabletools.com/docs/reference/layout.md) | Current Layout |
| [currentLayoutName](https://www.adaptabletools.com/docs/reference/basecolumnheadercontext.md#currentlayoutname) | `string` | Name of Current Layout |
| [currentLayoutType](https://www.adaptabletools.com/docs/reference/basecolumnheadercontext.md#currentlayouttype) | `'table' \| 'pivot'` | Type (table/pivot) of Current Layout |
| [defaultHeaderName](https://www.adaptabletools.com/docs/reference/basecolumnheadercontext.md#defaultheadername) | `string` | Resolved header name for the Column — the layout-specific header if one is defined, otherwise the ColDef header.<br/>This is the value that would be displayed when no `columnHeader` function is provided. |
| [layoutSpecificHeaderName](https://www.adaptabletools.com/docs/reference/basecolumnheadercontext.md#layoutspecificheadername) | `string` | Layout-specific header name for the Column, when one is defined in the current Layout&#39;s `ColumnHeaders`. |
| [adaptableContext](https://www.adaptabletools.com/docs/reference/basecolumnheadercontext.md#adaptablecontext) | `any` | Custom application Context provided in `AdaptableOptions.adaptableContext` |

<b>Table Columns</b>

Standard Table Layout Columns use [`TableColumnHeaderContext`](https://www.adaptabletools.com/docs/reference/tablecolumnheadercontext.md):

| Property | Type | Description |
| --- | --- | --- |
| [aggregation](https://www.adaptabletools.com/docs/reference/tablecolumnheadercontext.md#aggregation) | `string` | Aggregation function of Column (optional) |
| [columnId](https://www.adaptabletools.com/docs/reference/tablecolumnheadercontext.md#columnid) | `string` | Id of the Column |
| [columnType](https://www.adaptabletools.com/docs/reference/tablecolumnheadercontext.md#columntype) | `'tableColumn'` | Table Column (created in Table Layouts) |
| [adaptableContext](https://www.adaptabletools.com/docs/reference/tablecolumnheadercontext.md#adaptablecontext) | `any` | Custom application Context provided in `AdaptableOptions.adaptableContext` |

<b>Table Group Columns</b>

Table Layout Columns which are in a Column Group use [`TableColumnGroupHeaderContext`](https://www.adaptabletools.com/docs/reference/tablecolumngroupheadercontext.md):

| Property | Type | Description |
| --- | --- | --- |
| [childrenColumnIds](https://www.adaptabletools.com/docs/reference/tablecolumngroupheadercontext.md#childrencolumnids) | `string[]` | Ids of Column Group&#39;s children |
| [columnType](https://www.adaptabletools.com/docs/reference/tablecolumngroupheadercontext.md#columntype) | `'tableColumnGroup'` | Table Column Group (used when Column Grouping in Table Layouts) |
| [groupId](https://www.adaptabletools.com/docs/reference/tablecolumngroupheadercontext.md#groupid) | `string` | Id of Column Group |
| [state](https://www.adaptabletools.com/docs/reference/tablecolumngroupheadercontext.md#state) | `'expanded' \| 'collapsed'` | Expanded / Collapsed state of Column Group |
| [adaptableContext](https://www.adaptabletools.com/docs/reference/tablecolumngroupheadercontext.md#adaptablecontext) | `any` | Custom application Context provided in `AdaptableOptions.adaptableContext` |

<b>Auto Group Columns</b>

Auto Group Columns (created by AG Grid when Row Grouping is active) use [`AutoGroupColumnHeaderContext`](https://www.adaptabletools.com/docs/reference/autogroupcolumnheadercontext.md):

| Property | Type | Description |
| --- | --- | --- |
| [columnId](https://www.adaptabletools.com/docs/reference/autogroupcolumnheadercontext.md#columnid) | `string` | Id of the Column |
| [columnType](https://www.adaptabletools.com/docs/reference/autogroupcolumnheadercontext.md#columntype) | `'autoGroupColumn'` | Auto-generated Row Group Column (when RowGroupDisplayType is `single`) |
| [groupedColumnIds](https://www.adaptabletools.com/docs/reference/autogroupcolumnheadercontext.md#groupedcolumnids) | `string[]` | Ids of all Row Grouped Columns |
| [adaptableContext](https://www.adaptabletools.com/docs/reference/autogroupcolumnheadercontext.md#adaptablecontext) | `any` | Custom application Context provided in `AdaptableOptions.adaptableContext` |

<b>Row Group Columns</b>

Row Grouped Columns (created by AG Grid when Row Grouping is active) use [`RowGroupColumnHeaderContext`](https://www.adaptabletools.com/docs/reference/rowgroupcolumnheadercontext.md):

| Property | Type | Description |
| --- | --- | --- |
| [columnId](https://www.adaptabletools.com/docs/reference/rowgroupcolumnheadercontext.md#columnid) | `string` | Id of the Column |
| [columnType](https://www.adaptabletools.com/docs/reference/rowgroupcolumnheadercontext.md#columntype) | `'rowGroupColumn'` | A Row Grouped Column (created in both Table and Pivot Layout) |
| [groupColumnId](https://www.adaptabletools.com/docs/reference/rowgroupcolumnheadercontext.md#groupcolumnid) | `string` | Id of Row Grouped Column |
| [adaptableContext](https://www.adaptabletools.com/docs/reference/rowgroupcolumnheadercontext.md#adaptablecontext) | `any` | Custom application Context provided in `AdaptableOptions.adaptableContext` |

<b>Pivot Group Columns</b>

Pivot Group Columns are created by AG Grid for each distinct value in a Pivot Column, and use [`PivotColumnGroupHeaderContext`](https://www.adaptabletools.com/docs/reference/pivotcolumngroupheadercontext.md):

| Property | Type | Description |
| --- | --- | --- |
| [columnType](https://www.adaptabletools.com/docs/reference/pivotcolumngroupheadercontext.md#columntype) | `'pivotColumnGroup'` | Pivot Column Group (created for each distinct value in a PivotColumn) |
| [groupId](https://www.adaptabletools.com/docs/reference/pivotcolumngroupheadercontext.md#groupid) | `string` | Id of generated Column Group |
| [pivotKeys](https://www.adaptabletools.com/docs/reference/pivotcolumngroupheadercontext.md#pivotkeys) | `string[]` | Pivot Keys for Column Group |
| [state](https://www.adaptabletools.com/docs/reference/pivotcolumngroupheadercontext.md#state) | `'expanded' \| 'collapsed'` | Expanded / Collapsed state of Column Group |
| [adaptableContext](https://www.adaptabletools.com/docs/reference/pivotcolumngroupheadercontext.md#adaptablecontext) | `any` | Custom application Context provided in `AdaptableOptions.adaptableContext` |

<b>Pivot Result Columns</b>

Pivot Result Columns are dynamically created by AG Grid for each combination of Pivot Column value and Pivot Aggregation, and use [`PivotResultColumnHeaderContext`](https://www.adaptabletools.com/docs/reference/pivotresultcolumnheadercontext.md):

| Property | Type | Description |
| --- | --- | --- |
| [aggregatedColumnId](https://www.adaptabletools.com/docs/reference/pivotresultcolumnheadercontext.md#aggregatedcolumnid) | `string` | Id of Pivot Aggregated Column |
| [aggregation](https://www.adaptabletools.com/docs/reference/pivotresultcolumnheadercontext.md#aggregation) | `string` | Aggregation function of Column |
| [columnId](https://www.adaptabletools.com/docs/reference/pivotresultcolumnheadercontext.md#columnid) | `string` | Id of generated Column |
| [columnType](https://www.adaptabletools.com/docs/reference/pivotresultcolumnheadercontext.md#columntype) | `'pivotResultColumn'` | Pivot Result Column (unique intersection of PivotAggregationColumn and PivotColumn) |
| [pivotKeys](https://www.adaptabletools.com/docs/reference/pivotresultcolumnheadercontext.md#pivotkeys) | `string[]` | Current Pivot Keys |
| [adaptableContext](https://www.adaptabletools.com/docs/reference/pivotresultcolumnheadercontext.md#adaptablecontext) | `any` | Custom application Context provided in `AdaptableOptions.adaptableContext` |

<b>Pivot Grand Total Columns</b>

Pivot Grand Total Columns (used for [Pivot Totalling](https://www.adaptabletools.com/docs/handbook-layouts-pivot-total-columns/index.md)) use [`PivotGrandTotalHeaderContext`](https://www.adaptabletools.com/docs/reference/pivotgrandtotalheadercontext.md):

| Property | Type | Description |
| --- | --- | --- |
| [aggregatedColumnId](https://www.adaptabletools.com/docs/reference/pivotgrandtotalheadercontext.md#aggregatedcolumnid) | `string` | Id of Pivot Aggregated Column |
| [aggregation](https://www.adaptabletools.com/docs/reference/pivotgrandtotalheadercontext.md#aggregation) | `string` | Aggregation function of Column |
| [columnType](https://www.adaptabletools.com/docs/reference/pivotgrandtotalheadercontext.md#columntype) | `'pivotGrandTotal'` | Pivot Grand Total Column |
| [adaptableContext](https://www.adaptabletools.com/docs/reference/pivotgrandtotalheadercontext.md#adaptablecontext) | `any` | Custom application Context provided in `AdaptableOptions.adaptableContext` |

<b>Pivot Column Total Columns</b>

Pivot Column Total Columns (also used for [Pivot Totalling](https://www.adaptabletools.com/docs/handbook-layouts-pivot-total-columns/index.md)) use [`PivotColumnTotalHeaderContext`](https://www.adaptabletools.com/docs/reference/pivotcolumntotalheadercontext.md):

| Property | Type | Description |
| --- | --- | --- |
| [aggregation](https://www.adaptabletools.com/docs/reference/pivotcolumntotalheadercontext.md#aggregation) | `string` | Aggregation function of Column |
| [columnType](https://www.adaptabletools.com/docs/reference/pivotcolumntotalheadercontext.md#columntype) | `'pivotColumnTotal'` | Pivot Column Total |
| [pivotColumnId](https://www.adaptabletools.com/docs/reference/pivotcolumntotalheadercontext.md#pivotcolumnid) | `string` | Id of Pivot Column |
| [pivotKey](https://www.adaptabletools.com/docs/reference/pivotcolumntotalheadercontext.md#pivotkey) | `string` | Key (i.e. column value) of Pivot Column |
| [adaptableContext](https://www.adaptabletools.com/docs/reference/pivotcolumntotalheadercontext.md#adaptablecontext) | `any` | Custom application Context provided in `AdaptableOptions.adaptableContext` |

<b>Pivot Aggregation Total Columns</b>

Pivot Aggregation Total Columns (again also used for [Pivot Totalling](https://www.adaptabletools.com/docs/handbook-layouts-pivot-total-columns/index.md)) use [`PivotAggregationTotalHeaderContext`](https://www.adaptabletools.com/docs/reference/pivotaggregationtotalheadercontext.md):

| Property | Type | Description |
| --- | --- | --- |
| [aggregatedColumnId](https://www.adaptabletools.com/docs/reference/pivotaggregationtotalheadercontext.md#aggregatedcolumnid) | `string` | Id of Aggregated Column |
| [aggregation](https://www.adaptabletools.com/docs/reference/pivotaggregationtotalheadercontext.md#aggregation) | `string` | Aggregation function of Column |
| [columnType](https://www.adaptabletools.com/docs/reference/pivotaggregationtotalheadercontext.md#columntype) | `'pivotAggregationTotal'` | Pivot Aggregation Total Column |
| [pivotColumnId](https://www.adaptabletools.com/docs/reference/pivotaggregationtotalheadercontext.md#pivotcolumnid) | `string` | Id of Pivot Column |
| [pivotKey](https://www.adaptabletools.com/docs/reference/pivotaggregationtotalheadercontext.md#pivotkey) | `string` | Key (i.e. column value) of Pivot Column |
| [adaptableContext](https://www.adaptabletools.com/docs/reference/pivotaggregationtotalheadercontext.md#adaptablecontext) | `any` | Custom application Context provided in `AdaptableOptions.adaptableContext` |

**Example: Custom Column Headers Function**

Providing Alternative Column Headers via a function

- This demo shows how to change the Column Header programmatically. We change the Header for various types of columns (visible via different Layouts):
  - For `tableColumn` we change 'Name' to `JS Framework` (see `Table Layout`)
  - For `autoGroupColumn` we change the header to "My Row Group" (see `Row Grouped Layout`)
  - For `tableColumnGroup` we change the header to "My Column Group" (see `Column Group Layout`)
  - For `pivotResultColumn` we add prefix of "Agg" to header (see `Pivot Layout`)
  - For `pivotColumnGroup` we add prefix of "PC" to header (also see `Pivot Layout`)

- Switch between Layouts and see the different Headers
- Change the JavaScript Framework Column Header in the Layout Editor's Wizard — the function honours that user override via `layoutSpecificHeaderName`

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

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts
  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, ColumnHeaderContext} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'tradeId',
  userName: 'Demo User',
  adaptableId: 'Column Headers Function',
  columnOptions: {
    columnHeader: (context: ColumnHeaderContext) => {
      const {columnType, defaultHeaderName} = context;

      // Honour a caption the user set in the Layout
      if (context.layoutSpecificHeaderName) {
        return context.layoutSpecificHeaderName;
      }

      if (columnType == 'tableColumn') {
        if (context.columnId == 'name') {
          return 'JS Framework';
        }
      } else if (
        columnType == 'autoGroupColumn' &&
        context.currentLayoutType == 'table'
      ) {
        return 'My Row Group';
      } else if (columnType == 'pivotResultColumn') {
        return `Agg: ${defaultHeaderName}`;
      } else if (
        columnType == 'tableColumnGroup' &&
        context.currentLayoutType == 'table'
      ) {
        return 'My Column Group';
      } else if (columnType == 'pivotColumnGroup') {
        return `PC: ${defaultHeaderName}`;
      }
      return defaultHeaderName;
    },
  },
  initialState: {
    Dashboard: {
      Tabs: [
        {
          Name: 'Demo',
          Toolbars: ['Layout'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Table Layout',
      Layouts: [
        {
          Name: 'Table Layout',
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'updated_at',
            'has_wiki',
            'created_at',
            'pushed_at',
            'github_watchers',
          ],
          ColumnSizing: {
            name: {Width: 150},
          },
        },
        {
          Name: 'Row Grouped Layout',
          RowGroupedColumns: ['license'],
          TableAggregationColumns: [
            {
              ColumnId: 'github_watchers',
              AggFunc: 'sum',
            },
            {
              ColumnId: 'github_stars',
              AggFunc: 'sum',
            },
          ],
          SuppressAggFuncInHeader: true,
          TableColumns: [
            'name',
            'github_stars',
            'language',
            'github_watchers',
            'updated_at',
          ],
        },
        {
          Name: 'Column Group Layout',
          TableColumns: [
            'name',
            'language',
            'open_issues_count',
            'closed_issues_count',
            'github_stars',
            'license',
            'updated_at',
            'has_wiki',
            'created_at',
            'pushed_at',
            'github_watchers',
          ],
        },
        {
          Name: 'Pivot Layout',
          PivotColumns: ['license'],
          PivotGroupedColumns: ['language'],
          PivotAggregationColumns: [
            {ColumnId: 'github_watchers', AggFunc: 'sum'},
            {ColumnId: 'github_stars', AggFunc: 'sum'},
          ],
          SuppressAggFuncInHeader: 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: {
    sortable: true,
    filter: true,
    floatingFilter: true,
    enableRowGroup: true,
    wrapHeaderText: true,
    autoHeaderHeight: true,
  },
  columnDefs: columnDefs,
  rowData: rowData,
  sideBar: true,
};
```
**`src/columnDefs.ts`**

```ts
import {ColDef, ColGroupDef} from 'ag-grid-enterprise';

export const columnDefs: (ColDef | ColGroupDef)[] = [
  {
    field: 'id',
    cellDataType: 'number',
    hide: true,
    editable: false,
  },
  {
    field: 'name',
    cellDataType: 'text',
  },
  {
    headerName: 'Issues',
    marryChildren: true,
    children: [
      {
        field: 'open_issues_count',
        headerName: 'Open Issues',
        cellDataType: 'number',
        //  columnGroupShow: 'closed',
      },
      {
        field: 'closed_issues_count',
        headerName: 'Closed Issues',
        cellDataType: 'number',
        // columnGroupShow: 'closed',
      },
    ],
  },
  {
    field: 'language',
    cellDataType: 'text',
    enablePivot: true,
    enableRowGroup: true,
  },
  {
    field: 'created_at',
    headerName: 'Created',
    cellDataType: 'date',
  },

  {
    field: 'updated_at',
    headerName: 'Updated',
    cellDataType: 'date',
  },
  {
    field: 'pushed_at',
    headerName: 'Pushed',
    cellDataType: 'date',
  },

  {
    field: 'description',
    cellDataType: 'text',
    sortable: false,
    columnGroupShow: 'closed',
  },
  {
    field: 'license',
    cellDataType: 'text',
    editable: false,
    enablePivot: true,
    enableRowGroup: true,
  },

  {field: 'has_wiki', headerName: 'Has Wiki', cellDataType: 'boolean'},
  {
    field: 'has_projects',
    headerName: 'Has Projects',
    cellDataType: 'boolean',
  },
  {field: 'has_pages', headerName: 'Has Pages', cellDataType: 'boolean'},

  {
    field: 'github_stars',
    headerName: 'GitHub Stars',
    cellDataType: 'number',
    enableValue: true,
  },
  {
    field: 'github_watchers',
    headerName: 'GitHub Watchers',
    cellDataType: 'number',
    enableValue: true,
  },
  {
    field: 'week_issue_change',
    headerName: 'Issue Change',
    cellDataType: 'number',
    enableValue: true,
  },
];
```

## AG Grid Editable Header Names

AG Grid provides its own way to rename headers: setting `headerNameEditable` on a Column Definition (with `ColumnHeaderEditModule`) adds an `Edit Column Name` item to AG Grid's menus.

AdapTable does **not** integrate this feature, because AdapTable's own Column Header support already covers it and goes considerably further.

AdapTable Column Headers:

- are set per Layout, so the same Column can have a different caption in each Layout
- are saved in Adaptable State, together with the rest of the Layout
- can be shared with other users, as part of the Layout, via [Team Sharing](https://www.adaptabletools.com/docs/handbook-team-sharing/index.md)
- can be set at design-time in Initial State, at run-time in the Column Menu or the Layout Wizard, or programmatically via the Layout API
- can be computed by the `columnHeader` function, which covers Table Columns and Column Groups as well as Row Group, Pivot and Total Columns

A name edited in AG Grid, by contrast:

- is stored in AG Grid's Column State and Grid State rather than in the Layout, so it is not part of Adaptable State and cannot be shared via Team Sharing
- applies to every Layout, rather than to the Layout where it was set
- takes priority over the AdapTable header mechanism, hiding the Layout's `ColumnHeaders` caption and bypassing the `columnHeader` function for that Column

Enabling AG Grid's feature would therefore replace a more capable mechanism with a more limited one, so AdapTable renames Column Headers through the Layout only.

- AdapTable removes AG Grid's `Edit Column Name` item from the Column Menu, the Context Menu and the Columns Tool Panel menu
- Developers can add it back via `customColumnMenu` / `customContextMenu`, but names edited that way bypass the Layout

To let users rename a Column at run-time, use the `Change Caption` Column Menu item, the Layout Wizard or the `setColumnCaption` function in [Layout API](https://www.adaptabletools.com/docs/technical-reference-layouts/index.md)
