# Integrating AdapTable with AG Grid

Canonical page: https://www.adaptabletools.com/docs/getting-started-integration

- Integrating a TypeScript (framework-agnostic) AdapTable instance with AG Grid is straightforward
- You can either leverage the [adaptable-setup](https://www.adaptabletools.com/docs/getting-started-ai-skills-setup/index.md) AI Agent Skill or integrate manually
- Also 3 Framework wrappers available: [React](https://www.adaptabletools.com/docs/react-integration/index.md), [Angular](https://www.adaptabletools.com/docs/angular-integration/index.md) and [Vue](https://www.adaptabletools.com/docs/vue-integration/index.md)

This page shows how to create a "vanilla" AdapTable instance — one that does not use a UI-framework wrapper.

Like all the demos on this site, the example is in **TypeScript** (used by most developers using AdapTable).

## Integration Options

<IntegrationRoutes framework="vanilla" />

## Agent Integration

Simply leverage the [adaptable-setup](https://www.adaptabletools.com/docs/getting-started-ai-skills-setup/index.md) AI skill, providing all relevant information:

<AiSkill skill="adaptable-setup" embedded>
add AdapTable to this AG Grid app
<br />
set up AdapTable in a new TypeScript project with rows fetched from https://api.example.com/trades
</AiSkill>

## Manual Integration

### Minimum Working Example

This is a complete first AdapTable instance containing:

- two containers
- CSS
- AG Grid Modules
- unique primary key
- one Layout
- `Adaptable.init` implementation

```ts
import {
  LicenseManager,
  themeQuartz,
  type GridOptions,
  type Module,
} from 'ag-grid-enterprise';
import {AllEnterpriseModule} from 'ag-grid-enterprise';
import {AgChartsEnterpriseModule} from 'ag-charts-enterprise';
import {
  Adaptable,
  type AdaptableApi,
  type AdaptableOptions,
  type AdaptableReadyInfo,
  type AgGridConfig,
  type InitialState,
} from '@adaptabletools/adaptable';
import '@adaptabletools/adaptable/index.css';

LicenseManager.setLicenseKey('<AG_GRID_LICENSE_KEY_HERE>');

const agGridModules: Module[] = [
  AllEnterpriseModule.with(AgChartsEnterpriseModule),
];

const gridOptions: GridOptions = {
  theme: themeQuartz,
  columnDefs: [
    {headerName: 'Id', field: 'id', cellDataType: 'number'},
    {headerName: 'Make', field: 'make', filter: true, cellDataType: 'text'},
    {headerName: 'Model', field: 'model', editable: true, cellDataType: 'text'},
    {headerName: 'Price', field: 'price', cellDataType: 'number'},
  ],
  rowData: [
    {id: 1, make: 'Toyota', model: 'Yaris', price: 40000},
    {id: 2, make: 'Toyota', model: 'Corolla', price: 28000},
    {id: 3, make: 'Ford', model: 'Mondeo', price: 32000},
  ],
  cellSelection: true,
  sideBar: true,
};

const initialState: InitialState = {
  Dashboard: {
    PinnedToolbars: ['Layout', 'Export'],
  },
  Layout: {
    CurrentLayout: 'Cars',
    Layouts: [
      {
        Name: 'Cars',
        TableColumns: ['id', 'make', 'model', 'price'],
      },
    ],
  },
};

const adaptableOptions: AdaptableOptions = {
  licenseKey: '<ADAPTABLE_LICENSE_KEY_HERE>',
  primaryKey: 'id',
  userName: 'Demo User',
  adaptableId: 'Basic Setup',
  initialState,
};

const agGridConfig: AgGridConfig = {
  gridOptions,
  modules: agGridModules,
};

const adaptableApi: AdaptableApi = await Adaptable.init(
  adaptableOptions,
  agGridConfig
);

adaptableApi.eventApi.on(
  'AdaptableReady',
  ({adaptableApi, agGridApi}: AdaptableReadyInfo) => {
    adaptableApi.quickSearchApi.runQuickSearch('toy');
    agGridApi.autoSizeAllColumns();
  }
);
```

The HTML needs the two default containers:

```html
<body>
  <div id="adaptable"></div>
  <div id="grid" style="height:500px"></div>
</body>
```

### Detailed Guide to Creating a non-Framework AdapTable Instance (TypeScript)

These are the steps involved in creating a new (vanilla) AdapTable instance:

These 2 `div` elements should be named (ideally in this order):

- _adaptable_ - contains the AdapTable instance
- _grid_ - contains the AG Grid instance

```html
<body>
  <div id="adaptable"></div>
  <div id="grid" style="height:500px"></div>
</body>
```

- It is possible to name the Divs containing AG Grid and AdapTable differently (in place of the default values: _grid_ and _adaptable_)
- In this case, provide these names in [`ContainerOptions`](https://www.adaptabletools.com/docs/reference/containeroptions.md) - see [Providing bespoke AdapTable and AG Grid div Ids](https://www.adaptabletools.com/docs/getting-started-setting-adaptable-aggrid-containers/index.md) for more details (also if using a Shadow DOM)

`index.css` contains core styles (and supports both `light` and `dark` themes)

```ts
import '@adaptabletools/adaptable/index.css';
```

- AdapTable's styles use the `adaptable` CSS layer - so you can access that to control specificity
- If your app is using Tailwind, we recommend using this CSS layer order: `@layer theme, base, components, adaptable, utilities`
- See [AdapTable Theming Guide](https://www.adaptabletools.com/docs/handbook-theming/index.md) for full details on choosing and extending AdapTable Themes

Import the main `Adaptable` object and any required types from `@adaptabletools/adaptable`.

Everything is a named export.

```ts
import {
  Adaptable,
  type AdaptableApi,
  type AdaptableOptions,
  type AdaptableReadyInfo,
  type AgGridConfig,
  type InitialState,
} from '@adaptabletools/adaptable';
```

Import the [AG Grid Enterprise Modules](https://www.adaptabletools.com/docs/getting-started-aggrid-modules/index.md).

The support templates use the Enterprise bundle together with AG Charts. That covers AG Grid Charts and [AdapTable Sparkline Columns](https://www.adaptabletools.com/docs/handbook-styled-column-sparkline/index.md).

```ts
import {AllEnterpriseModule, type Module} from 'ag-grid-enterprise';
import {AgChartsEnterpriseModule} from 'ag-charts-enterprise';

export const agGridModules: Module[] = [
  AllEnterpriseModule.with(AgChartsEnterpriseModule),
];
```

- To register only the modules your feature set needs, see [AG Grid Modules](https://www.adaptabletools.com/docs/getting-started-aggrid-modules/index.md)
- In AG Grid 36 the Client-Side Row Model is part of the grid core, so `ClientSideRowModelModule` is not required

Define and populate a standard [AG Grid GridOptions](https://www.ag-grid.com/javascript-data-grid/grid-interface/#grid-options) object.

Provide all required AG Grid related information including:

- AG Grid theme (`themeQuartz` in this example)
- column schema via `columnDefs` (including the correct [cell data types](https://www.adaptabletools.com/docs/dev-guide-aggrid-cell-data-types/index.md))
- initial data (if not lazy loading)
- AG Grid events
- any additional, required properties

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

const gridOptions: GridOptions = {
  theme: themeQuartz,
  columnDefs: [
    {headerName: 'Id', field: 'id', cellDataType: 'number'},
    {headerName: 'Make', field: 'make', filter: true, cellDataType: 'text'},
    {headerName: 'Model', field: 'model', editable: true, cellDataType: 'text'},
    {headerName: 'Price', field: 'price', cellDataType: 'number'},
  ],
  rowData: [
    {id: 1, make: 'Toyota', model: 'Yaris', price: 40000},
    {id: 2, make: 'Toyota', model: 'Corolla', price: 28000},
    {id: 3, make: 'Ford', model: 'Mondeo', price: 32000},
  ],
  cellSelection: true,
  sideBar: true,
};
```

- Many ColDef properties are **ignored** by AdapTable and replaced by [Layout](https://www.adaptabletools.com/docs/handbook-layouts/index.md) props - see full details in [Guide to Layouts and ColDefs](https://www.adaptabletools.com/docs/dev-guide-columns-configuring-coldefs/index.md)
- **Do not instantiate AG Grid**; AdapTable will do that itself, together with any required wiring up of objects

- Always set the appropriate `cellDataType` property in ColumnDefs for each Column that is defined
- This will enable AdapTable to use the correct set of Filters and related properties - see [Setting Cell Data Types](https://www.adaptabletools.com/docs/dev-guide-aggrid-cell-data-types/index.md) for more information

- AG Grid Enterprise also requires its own license key
- Set it with `LicenseManager.setLicenseKey` from `ag-grid-enterprise` (the support template shows this)

Add the [Initial Adaptable State](https://www.adaptabletools.com/docs/dev-guide-adaptable-state-initial-state/index.md) that is required to ship AdapTable with the objects you require for **initial** use.

This will later get merged into [Adaptable State](https://www.adaptabletools.com/docs/dev-guide-adaptable-state/index.md), together with any changes made by the run-time user.

It **must** include a `Layouts` section, containing at least one [Layout](https://www.adaptabletools.com/docs/handbook-layouts/index.md) (unless using [Default Layouts](https://www.adaptabletools.com/docs/handbook-layouts-default/index.md)).

In this example we:

- Pin the `Layout` and `Export` Toolbars on the [Dashboard](https://www.adaptabletools.com/docs/ui-dashboard/index.md)
- Create a [Layout](https://www.adaptabletools.com/docs/handbook-layouts/index.md) "Cars" whose ColumnIds match the ColDef `field` values

```ts
const initialState: InitialState = {
  Dashboard: {
    PinnedToolbars: ['Layout', 'Export'],
  },
  Layout: {
    CurrentLayout: 'Cars',
    Layouts: [
      {
        Name: 'Cars',
        TableColumns: ['id', 'make', 'model', 'price'],
      },
    ],
  },
};
```

[Adaptable Options](https://www.adaptabletools.com/docs/technical-reference-adaptable-options/index.md) defines exactly how AdapTable should work.

Every instance needs:

- a [Primary Key](https://www.adaptabletools.com/docs/getting-started-primary-key/index.md) — a unique column
- an [Adaptable Id](https://www.adaptabletools.com/docs/getting-started-adaptable-id/index.md) which uniquely identifies the Grid
- the [License Key](https://www.adaptabletools.com/docs/getting-started-license-key/index.md) provided when purchasing AdapTable
- a [User Name](https://www.adaptabletools.com/docs/getting-started-user-name/index.md) to identify the current user
- the `initialState` created above

```ts
const adaptableOptions: AdaptableOptions = {
  licenseKey: '<ADAPTABLE_LICENSE_KEY_HERE>',
  primaryKey: 'id',
  userName: 'Demo User',
  adaptableId: 'Basic Setup',
  initialState,
};
```

Adaptable Options supports [TypeScript Generics](https://www.adaptabletools.com/docs/technical-reference-adaptable-options/index.md#typescript-generics) which ensures a better developer experience by providing the row data type

If the `licenseKey` property is not present, AdapTable will display a watermark and run with reduced functionality

Often added next: [Entitlements](https://www.adaptabletools.com/docs/handbook-permissioning/index.md), [Plugins](https://www.adaptabletools.com/docs/technical-reference-plugins/index.md), and [remote State persistence](https://www.adaptabletools.com/docs/dev-guide-adaptable-state-persistence/index.md#remote-storage)

The static async AdapTable constructor receives 2 objects:

- the [Adaptable Options](https://www.adaptabletools.com/docs/technical-reference-adaptable-options/index.md) created in Step 7
- an [`AgGridConfig`](https://www.adaptabletools.com/docs/reference/aggridconfig.md) object which contains two properties:
  - `gridOptions` — the Grid Options object created in Step 5
  - `modules` — the AG Grid Modules defined in Step 4

It returns (via a Promise) an [Adaptable API](https://www.adaptabletools.com/docs/technical-reference-adaptable-api/index.md) object - which gives run time access to all AdapTable functionality.

```ts
const agGridConfig: AgGridConfig = {
  gridOptions,
  modules: agGridModules,
};

const adaptableApi: AdaptableApi = await Adaptable.init(
  adaptableOptions,
  agGridConfig
);
```

Add listener to [Adaptable Ready Event](https://www.adaptabletools.com/docs/getting-started-adaptable-ready/index.md) which fires when AdapTable is initialised.

This should be used to perform any required setup-related actions.

The [`AdaptableReadyInfo`](https://www.adaptabletools.com/docs/reference/adaptablereadyinfo.md) object provided by the Event contains two key objects:

- `adaptableApi` which gives access to the [Adaptable API](https://www.adaptabletools.com/docs/technical-reference-adaptable-api/index.md)
- `agGridApi` which gives access to [AG Grid's Api](https://www.ag-grid.com/javascript-data-grid/reference/)

```ts
adaptableApi.eventApi.on(
  'AdaptableReady',
  ({adaptableApi, agGridApi}: AdaptableReadyInfo) => {
    adaptableApi.quickSearchApi.runQuickSearch('toy');
    agGridApi.autoSizeAllColumns();
  }
);
```

If you are using TypeScript then you must use version 5.8.3 or higher

See the related articles in this documentation for more detailed instructions on:
- [Choosing a Primary Key](https://www.adaptabletools.com/docs/getting-started-primary-key/index.md)
- [Setting the Adaptable Id](https://www.adaptabletools.com/docs/getting-started-adaptable-id/index.md)
- [Providing a User Name](https://www.adaptabletools.com/docs/getting-started-user-name/index.md)
- [Creating Adaptable Context](https://www.adaptabletools.com/docs/dev-guide-tutorial-providing-adaptable-context/index.md)
- [Configuring the Adaptable State Key](https://www.adaptabletools.com/docs/getting-started-adaptable-state-key/index.md)
- [Providing Initial Adaptable State](https://www.adaptabletools.com/docs/dev-guide-adaptable-state-initial-state/index.md)
- [Managing Remote State Persistence](https://www.adaptabletools.com/docs/dev-guide-adaptable-state-persistence/index.md#remote-storage)
- [Supplying the AdapTable License Key](https://www.adaptabletools.com/docs/getting-started-license-key/index.md)
- [Layouts vs ColDefs](https://www.adaptabletools.com/docs/dev-guide-columns-configuring-coldefs/index.md)
- [Setting Cell Data Types](https://www.adaptabletools.com/docs/dev-guide-aggrid-cell-data-types/index.md)
- [Listening to Adaptable Ready Event](https://www.adaptabletools.com/docs/getting-started-adaptable-ready/index.md)
- [Testing AdapTable](https://www.adaptabletools.com/docs/getting-started-testing/index.md)
- [Selecting or Creating an AdapTable Theme](https://www.adaptabletools.com/docs/handbook-theming/index.md)

## Accessing AdapTable at Run-Time

The [Adaptable API](https://www.adaptabletools.com/docs/technical-reference-adaptable-api/index.md) has many hundreds of methods to allow full, programmatic access to all AdapTable functionality and state at run-time.

It also includes an `eventApi` section for listening to [Adaptable Events](https://www.adaptabletools.com/docs/technical-reference-adaptable-events/index.md).

The same API is how you write tests: wait for [Adaptable Ready](https://www.adaptabletools.com/docs/getting-started-adaptable-ready/index.md), then assert through the API. See [Testing AdapTable](https://www.adaptabletools.com/docs/getting-started-testing/index.md).

## Destroying AdapTable

It is possible to programmatically destroy - and clean up - an AdapTable session.

This is done by using the `destroy` function, available in the root of [`Adaptable API`](https://www.adaptabletools.com/docs/reference/adaptableapi.md#destroy).

- This function is only needed for the vanilla version of AdapTable
- All 3 Framework wrappers handle unmount and cleanup as part of the application lifecycle

The function performs 2 important actions:

- unmounts the Adaptable component
- destroys the AG Grid instance.

### FAQ

**Why do I see an error message saying `There is no DIV with id=[Name] so cannot render Adaptable`?**
You have likely supplied a bespoke value for the `adaptableContainer` property in [Container Options](https://www.adaptabletools.com/docs/getting-started-setting-adaptable-aggrid-containers/index.md) but not provided a Div with the same name.

**I am using Stencil and cannot see AdapTable?**
[Stencil](https://stenciljs.com/) uses a shadow DOM, so you need to specify the `agGridContainer` and `adaptableContainer` in `adaptableOptions.containerOptions` as elements, not as strings.
If you have `scoped: true` then use:

```
this.el.shadowRoot.querySelector(...)
```

to retrieve references to your vendor grid & adaptable container elements.

If you have `scoped: false` you should use:

```
this.el.querySelector(...)
```

Common first-run questions (modules, cell data types, browsers, watermarks) are on the [Getting Started FAQ](https://www.adaptabletools.com/docs/getting-started-faq/index.md).
