# Managing AG Grid Column Defs at RunTime

Canonical page: https://www.adaptabletools.com/docs/dev-guide-columns-managing-runtime

- AdapTable helps developers manage AG Grid Column Definitions easily and safely updated at runtime
- Two convenience functions reduce the update's complexity while ensuring AdapTable's [Layouts](https://www.adaptabletools.com/docs/handbook-layouts/index.md) work smoothly
- Other functions enable Column Definitions to be safely added and removed at runtime

AG Grid's Column Definitions are **immutable**.

Nevertheless, AG Grid still makes it possible, at runtime, to add, update or delete ColDefs.

AdapTable supports this functionality via bespoke "wrapper" functions to ensure everything hangs together.

These functions ensure that AG Grid columns are added, updated or deleted correctly, while also ensuring AdapTable's [Layouts](https://www.adaptabletools.com/docs/handbook-layouts/index.md) and other features run smoothly.

- **We strongly recommend you use AdapTable's API functions** (listed below) when managing AG Grid columns
- AdapTable will invoke the related AG Grid function, but in a way that ensures everything hangs together properly

## Updating ColDefs

AG Grid distinguishes between 2 types of Column properties - **stateful** and **non-stateful**.

It provides 2 complementary sets of `GridAPI` functions to update column props based on this distinction:

- For the reduced set of "stateful" Column properties the [AG Grid Column State API](https://www.ag-grid.com/javascript-data-grid/column-state/) is recommended
- For all other Column properties [AG Grid's Grid API](https://www.ag-grid.com/javascript-data-grid/column-updating-definitions/) should be used

AdapTable fully supports AG Grid Column immutability, and also how columns can be updated at run-time.  

AdapTable's [Grid API](https://www.adaptabletools.com/docs/handbook-managing-grid-data/index.md) contains 2 sets of complementary functions to mirror those provided by AG Grid.

- AdapTable provides 2 different sets of methods for stateful and non-stateful Column properties
- However the shape of the object that is passsed into each function is identical

### Stateful Properties

As noted above, AG Grid defines a subset of column properties as [Column State](https://www.ag-grid.com/javascript-data-grid/column-updating-definitions/#changing-column-state).

These are properties which can be updated without needing to provide a full new set of Column definitions.

AdapTable provides the `updateAgGridColumnState` function in [`GridApi`](https://www.adaptabletools.com/docs/reference/gridapi.md) to update the Column State for a Column in a safe way.

A parallel `updateAgGridColumnStates` function can be used to update the Column State for **multiple** columns

### `updateAgGridColumnState`

Updates the Column State for a given Column

The function take an AG Grid Column State object (of type `ColumnState`) and returns void.

You should pass in an object that contains the `colId` of the column and whichever stateful property (or properties) you want to change:

```ts
// Hide the Rating column
adaptableApi.gridApi.updateAgGridColumnState({
  colId: 'rating',
  hide: true,
});
``` 

The function will, in turn, call AG Grid's `applyColumnState` function in AG Grid Api in a managed way.

**Example: Updating Stateful Column Props at Runtime**

How to safely update AG Grid Column properties using Column State at run-time

 

- In this demo a Custom Dashboard Toolbar contains 3 buttons that each update **stateful** AG Grid Column props using the `updateAgGridColumnState` function:
  - The `Name` column is widened using `width`
  - The `Language` column is hidden using `hide`
  - The `Github Stars` column is sorted and pinned using `sort` and `pin`

### Expand to see how the Column Definitions are updated

```ts
context.adaptableApi.gridApi.updateAgGridColumnState({
  colId: 'name',
  width: 300,
});

context.adaptableApi.gridApi.updateAgGridColumnState({
  colId: 'language',
  hide: true,
});

context.adaptableApi.gridApi.updateAgGridColumnState({
  colId: 'github_stars',
  pinned: 'right',
  sort: 'asc',
});
```

- Click each button in turn and see how they update

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

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

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Updating Stateful Column Defs',
  dashboardOptions: {
    customToolbars: [
      {
        name: 'Custom Buttons',
        toolbarButtons: [
          {
            label: 'Widen Name Column',
            buttonStyle: {
              tone: 'info',
              variant: 'outlined',
            },
            onClick: (
              _button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.gridApi.updateAgGridColumnState({
                colId: 'name',
                width: 300,
              });
            },
          },
          {
            label: 'Hide Language Column',
            buttonStyle: {
              tone: 'success',
              variant: 'outlined',
            },
            onClick: (
              _button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.gridApi.updateAgGridColumnState({
                colId: 'language',
                hide: true,
              });
            },
          },
          {
            label: 'Sort & Right-Pin Github Stars Column',
            buttonStyle: {
              tone: 'warning',
              variant: 'outlined',
            },
            onClick: (
              _button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.gridApi.updateAgGridColumnState({
                colId: 'github_stars',
                pinned: 'right',
                sort: 'asc',
              });
            },
          },
        ],
      },
    ],
  },
  initialState: {
    Dashboard: {
      PinnedToolbars: ['Custom Buttons'],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'license',
            'language',
            'week_issue_change',
            'github_watchers',
            'github_stars',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'open_issues_count',
            'open_pr_count',
            'closed_pr_count',
            'has_projects',
            'has_pages',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

### Non-Stateful Properties

Adaptable also fully supports updating Column properties which are not stateful.

This is done using the `updateAgGridColumnDefinition` function in [`GridApi`](https://www.adaptabletools.com/docs/reference/gridapi.md).

### `updateAgGridColumnDefinition`

Updates non-stateful properties in an AG Grid Column

The function take a [`ColDefWithId`](https://www.adaptabletools.com/docs/reference/coldefwithid.md) object and returns void.  

The `ColDefWithId` object is essentially an AG Grid Column Definition with a **mandatory** `colId` property.

To use the function, you need to pass in an object that contains the `colId` of the column and whichever non-stateful property (or properties) you want to change:

```ts
// Change the type and editable properties of the Rating column
adaptableApi.gridApi.updateAgGridColumnDefinition({
  colId: 'rating',
  type: ['newCustomType'],
  editable: true
});
``` 

**Example: Updating Other Column Props at Runtime**

How to safely update non-stateful AG Grid Column properties at run-time

 

- In this example the Custom Dashboard Toolbar again contains 3 buttons that each updates a Column Definition property
- But as these are **non-stateful** AG Grid Column props, the `updateAgGridColumnDefinition` function is used:
  - The `Name` column is given a new `headerName` of 'Framework'
  - The `License` column has `editable` set to *true*
  - The `Issue Change` column is given a [Column Type](https://www.adaptabletools.com/docs/dev-guide-columns-column-types/index.md) of 'Github' (because an existing [Format Column](https://www.adaptabletools.com/docs/handbook-column-formatting/index.md) has a Scope of that Column Type, the `Issue Change` Column is automatically styled)

### Expand to see how the Column Definitions are updated

```ts
context.adaptableApi.gridApi.updateAgGridColumnDefinition({
  colId: 'name',
  headerName: 'Framework',
});

context.adaptableApi.gridApi.updateAgGridColumnDefinition({
  colId: 'license',
  editable: true,
});

context.adaptableApi.gridApi.updateAgGridColumnDefinition({
  colId: 'week_issue_change',
  type: ['github'],
});
```

- Click each button in turn and see how they update

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

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Updating Non Stateful Column Defs',
  columnOptions: {
    columnTypes: ['github'],
  },
  dashboardOptions: {
    customToolbars: [
      {
        name: 'Custom Buttons',
        toolbarButtons: [
          {
            label: 'Change Name Column Header',
            buttonStyle: {
              tone: 'info',
              variant: 'outlined',
            },
            onClick: (
              _button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.gridApi.updateAgGridColumnDefinition({
                colId: 'name',
                headerName: 'Framework',
              });
            },
          },
          {
            label: 'Make License Editable',
            buttonStyle: {
              tone: 'success',
              variant: 'outlined',
            },
            onClick: (
              _button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.gridApi.updateAgGridColumnDefinition({
                colId: 'license',
                editable: true,
              });
            },
          },
          {
            label: 'Change Issue Change Style',
            buttonStyle: {
              tone: 'warning',
              variant: 'outlined',
            },
            onClick: (
              _button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.gridApi.updateAgGridColumnDefinition({
                colId: 'week_issue_change',
                type: ['github'],
                cellDataType: 'number',
              });
            },
          },
        ],
      },
    ],
  },
  initialState: {
    Dashboard: {
      PinnedToolbars: ['Custom Buttons'],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'week_issue_change',
            'github_watchers',
            'github_stars',
            'license',
            'language',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'open_issues_count',
            'open_pr_count',
            'closed_pr_count',
            'has_projects',
            'has_pages',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
    FormatColumn: {
      FormatColumns: [
        {
          Name: 'formatColumn-github',
          Scope: {
            ColumnTypes: ['github'],
          },
          Style: {
            ForeColor: 'LightBlue',
            FontWeight: 'Bold',
            Alignment: 'Center',
          },
        },
      ],
    },
  },
};
```
**`src/columnDefs.ts`**

```ts
import {ColDef} from 'ag-grid-enterprise';
import {WebFramework} from './rowData';

export const columnDefs: ColDef<WebFramework>[] = [
  {
    field: 'name',
    cellDataType: 'text',
    sortable: true,
  },
  {
    field: 'language',
    cellDataType: 'text',
    enablePivot: true,
    enableRowGroup: true,
  },
  {
    field: 'github_stars',
    headerName: 'GitHub Stars',
    cellDataType: 'number',
    type: 'github',
    enableValue: true,
  },
  {
    field: 'github_watchers',
    headerName: 'GitHub Watchers',
    cellDataType: 'number',
    type: 'github',
    enableValue: true,
  },
  {
    field: 'license',
    cellDataType: 'text',
    editable: false,
    enablePivot: true,
    enableRowGroup: true,
  },
  {
    field: 'week_issue_change',
    headerName: 'Issue Change',
    cellDataType: 'number',
    enableValue: true,
  },
  {
    field: 'rating',
    headerName: 'Rating',
    cellDataType: 'number',
    enableValue: true,
  },
  {
    field: 'created_at',
    headerName: 'Created',
    cellDataType: 'date',
  },
  {
    field: 'has_wiki',
    headerName: 'Has Wiki',
    cellDataType: 'boolean',
    enablePivot: true,
    enableRowGroup: true,
  },
  {
    field: 'updated_at',
    headerName: 'Updated',
    cellDataType: 'date',
  },
  {
    field: 'pushed_at',
    headerName: 'Pushed',
    cellDataType: 'date',
  },
  {
    field: 'description',
    cellDataType: 'text',
    sortable: false,
  },
  {
    field: 'open_issues_count',
    headerName: 'Open Issues',
    cellDataType: 'number',
    enableValue: true,
  },
  {
    field: 'closed_issues_count',
    headerName: 'Closed Issues',
    cellDataType: 'number',
    enableValue: true,
  },
  {
    field: 'open_pr_count',
    headerName: 'Open PRs',
    cellDataType: 'number',
    enableValue: true,
  },
  {
    field: 'closed_pr_count',
    headerName: 'Closed PRs',
    cellDataType: 'number',
    enableValue: true,
  },
  {
    field: 'has_projects',
    headerName: 'Has Projects',
    cellDataType: 'boolean',
  },
  {
    field: 'has_pages',
    headerName: 'Has Pages',
    cellDataType: 'boolean',
  },
  {
    field: 'topics',
    cellDataType: 'textArray',
    editable: false,
    sortable: false,
  },
  {
    field: 'id',
    cellDataType: 'number',
    hide: true,
    editable: false,
  },
];
```
**`src/gridOptions.ts`**

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

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

export const gridOptions: GridOptions<WebFramework> = {
  theme: themeBalham,
  defaultColDef: {
    resizable: true,
    sortable: true,
    editable: true,
    filter: true,
    floatingFilter: true,
  },
  columnDefs: columnDefs,
  rowData: rowData,
  sideBar: true,
  suppressMenuHide: true,
  columnMenu: 'new',
  cellSelection: true,
  statusBar: {
    statusPanels: [
      {statusPanel: 'agTotalRowCountComponent', align: 'left'},
      {statusPanel: 'agFilteredRowCountComponent'},
      {
        key: 'Center Panel',
        statusPanel: 'AdaptableStatusPanel',
        align: 'center',
      },
    ],
  },
  columnTypes: {
    github: {},
  },
};
```

 
## Adding & Removing ColDefs

AdapTable's [`GridApi`](https://www.adaptabletools.com/docs/reference/gridapi.md) contains 3 functions to safely add and remove AG Grid Column Definitions at run-time:
- `addAgGridColumnDefinition` - adds one ColumnDef
- `removeAgGridColumnDefinition` - removes one ColumnDef
- `setAgGridColumnDefinitions` - replaces **all** ColumnDefs

- Always use these function when adding new Columns, or removing existing Columns, at runtime
- AdapTable will make sure to add or remove column in ColumnDefs correctly and ensure everything works

### Adding ColDefs

The `addAgGridColumnDefinition` function enables a new AG Grid Column Definition to be added at run-time.

### `addAgGridColumnDefinition`

Adds new AG Grid Columns

The function take a [`ColDefWithId`](https://www.adaptabletools.com/docs/reference/coldefwithid.md) object and returns void.

The `ColDefWithId` object is essentially an AG Grid Column Definition with a mandatory `colId` property.

To use the function, you need to pass in an object that contains the `colId` of the column and whichever properties you want the Column to have:

```ts
// Provide a Rating column
adaptableApi.gridApi.addAgGridColumnDefinition({
  colId: 'rating',
  field: 'fitch',
  width: 200,
  editable: false,
  cellDataType: 'text'
});
```

 

**Example: Adding Column Definitions at Runtime**

How to safely add AG Grid Column Definitions at run-time

 

- In this example we provide a button that adds a `Forks Count` column using the `addAgGridColumnDefinition` function
- We then use the `updateCurrentLayout` function in [Layout API](https://www.adaptabletools.com/docs/technical-reference-layouts/index.md) to update the Layout to include the newly created column (see [Updating Layouts](https://www.adaptabletools.com/docs/handbook-layouts-updating/index.md) for more details)

### Expand to see how the Column Definition is added

```ts
context.adaptableApi.gridApi.addAgGridColumnDefinition({
  colId: 'forks_count',
  headerName: 'Forks Count',
  field: 'forks_count',
  width: 200,
  cellDataType: 'number'
});
```

- Click the button to add a `Forks Count` column (and note how it is added to the Layout)

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

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

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Adding Column Defs',
  dashboardOptions: {
    customToolbars: [
      {
        name: 'Custom Buttons',
        toolbarButtons: [
          {
            label: 'Add Forks Count Column',
            buttonStyle: {
              tone: 'info',
              variant: 'outlined',
            },
            onClick: (
              _button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.gridApi.addAgGridColumnDefinition({
                colId: 'forks_count',
                headerName: 'Forks Count',
                field: 'forks_count',
                width: 200,
                cellDataType: 'number',
              });

              context.adaptableApi.layoutApi.updateCurrentLayout(layout => {
                layout.TableColumns?.push('forks_count');
                return layout;
              });
            },
          },
        ],
      },
    ],
  },
  initialState: {
    Dashboard: {
      PinnedToolbars: ['Custom Buttons'],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'week_issue_change',
            'github_watchers',
            'github_stars',
          ],
        },
      ],
    },
  },
};
```

 

### Removing ColDefs

The `removeAgGridColumnDefinition` function enables safe run-time deletion of existing AG Grid ColDefs.

### `removeAgGridColumnDefinition`

Removes existing AG Grid Columns

The function takes the `colId` of the Column to be removed and returns void:

```ts
// Remove the Rating column
adaptableApi.gridApi.removeAgGridColumnDefinition('rating');
```

**Example: Deleting Column Definitions at Runtime**

How to safely remove AG Grid Column Definitions at run-time

 

- In this example we provide a button that deletes the `License` column using the `removeAgGridColumnDefinition` function.

### Expand to see how the Column Definition is deleted

```ts
context.adaptableApi.gridApi.removeAgGridColumnDefinition('license');
```

- Click the button to remove the `License` column

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

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

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Deleting Column Defs',
  dashboardOptions: {
    customToolbars: [
      {
        name: 'Custom Buttons',
        toolbarButtons: [
          {
            label: 'Delete License Column',
            buttonStyle: {
              tone: 'info',
              variant: 'outlined',
            },
            onClick: (
              _button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.gridApi.removeAgGridColumnDefinition(
                'license'
              );
            },
          },
        ],
      },
    ],
  },
  initialState: {
    Dashboard: {
      PinnedToolbars: ['Custom Buttons'],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'week_issue_change',
            'license',
            'language',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'github_watchers',
            'github_stars',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

 

### Setting ColDefs

The `setAgGridColumnDefinitions` function **replaces** the full set of AG Grid Column Definitions at run-time in a single step.

### `setAgGridColumnDefinitions`

Replace all AG Grid Columns

The function takes an array of AG Grid `ColDef` (or `ColGroupDef`) objects and returns void. It replaces every existing ColDef — it does not merge with the current set.

```ts
// Replace all AG Grid ColDefs
adaptableApi.gridApi.setAgGridColumnDefinitions(colDefs);
```

**Example: Setting Column Definitions at Runtime**

How to safely replace AG Grid Column Definitions at run-time

 

- In this example the grid starts with many columns visible
- Clicking the button replaces **all** Column Definitions in a single step using the `setAgGridColumnDefinitions` function
- The new set contains just 4 columns: `Framework`, `Language`, `GitHub Stars` and `License`
- The current [Layout](https://www.adaptabletools.com/docs/handbook-layouts/index.md) is also updated so it stays in sync with the new columns (see [Updating Layouts](https://www.adaptabletools.com/docs/handbook-layouts-updating/index.md) for more details)

### Expand to see how the Column Definitions are set

```ts
const compactColumnDefs = [
  {
    colId: 'name',
    field: 'name',
    headerName: 'Framework',
    cellDataType: 'text',
    width: 200,
  },
  {
    colId: 'language',
    field: 'language',
    cellDataType: 'text',
    width: 150,
  },
  {
    colId: 'github_stars',
    field: 'github_stars',
    headerName: 'GitHub Stars',
    cellDataType: 'number',
    width: 150,
  },
  {
    colId: 'license',
    field: 'license',
    cellDataType: 'text',
    width: 180,
  },
];

context.adaptableApi.gridApi.setAgGridColumnDefinitions(compactColumnDefs);

context.adaptableApi.layoutApi.updateCurrentLayout(layout => {
  layout.TableColumns = ['name', 'language', 'github_stars', 'license'];
  return layout;
});
```

- Click the button to replace the Column Definitions with the compact set (and note how the Layout is updated)

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

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

const compactColumnDefs = [
  {
    colId: 'name',
    field: 'name',
    headerName: 'Framework',
    cellDataType: 'text',
    width: 200,
  },
  {
    colId: 'language',
    field: 'language',
    cellDataType: 'text',
    width: 150,
  },
  {
    colId: 'github_stars',
    field: 'github_stars',
    headerName: 'GitHub Stars',
    cellDataType: 'number',
    width: 150,
  },
  {
    colId: 'license',
    field: 'license',
    cellDataType: 'text',
    width: 180,
  },
];

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Setting Column Defs',
  dashboardOptions: {
    customToolbars: [
      {
        name: 'Custom Buttons',
        toolbarButtons: [
          {
            label: 'Set Compact Column Definitions',
            buttonStyle: {
              tone: 'info',
              variant: 'outlined',
            },
            onClick: (
              _button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.gridApi.setAgGridColumnDefinitions(
                compactColumnDefs
              );

              context.adaptableApi.layoutApi.updateCurrentLayout(layout => {
                layout.TableColumns = [
                  'name',
                  'language',
                  'github_stars',
                  'license',
                ];
                return layout;
              });
            },
          },
        ],
      },
    ],
  },
  initialState: {
    Dashboard: {
      PinnedToolbars: ['Custom Buttons'],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'week_issue_change',
            'license',
            'language',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'github_watchers',
            'github_stars',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```
