# AdapTable - Key Concepts

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

- When developing with AdapTable there are 3 basic concepts to understand:
  - **Adaptable Options** — how to configure your AdapTable instance
  - **Initial Adaptable State** — the objects you provide to your application for first-time use
  - **Adaptable API** — how to access AdapTable at run-time

## The 3 Main Classes

The three classes below are key to getting started and making AdapTable work for you.

### Adaptable Options

Adaptable Options is a large group of property options which you **configure at design-time**.

This allows you to set up AdapTable so that it fits the requirements of the containing application.

The available properties include the the `adaptableId` and many groups of related options (e.g. Entitlements, Layout, Search, Edit, Menu etc.)

- Many of the options are JavaScript functions which, if provided, AdapTable will invoke when required
- Adaptable Options also includes the underlying [Initial Adaptable State](https://www.adaptabletools.com/docs/dev-guide-adaptable-state-initial-state/index.md)

Learn more about the options available in [Adaptable Options Reference](https://www.adaptabletools.com/docs/technical-reference-adaptable-options/index.md)

### Initial Adaptable State

Initial State is a group of objects written in JSON that you will **define at Design Time**.

- Providing AdapTable Initial State is optional
- However a `Layout` section, with at least one [Layout](https://www.adaptabletools.com/docs/handbook-layouts/index.md), is mandatory (unless [Creating a Default Layout](https://www.adaptabletools.com/docs/handbook-layouts-default/index.md) is configured)

It includes all the AdapTable Objects required for initial use of your hosted application e.g. Layouts, Filters, Reports, Alerts, Format Columns etc.

- Adaptable Initial State contains persistable objects and properties which **can change during Application run-time**
- Adaptable Options contains behaviour and functionality that **will never change** post-creation

The workflow is as follows:
1. The application starts for the first time and Initial Adaptable State is loaded
2. The State is then merged with any run-time changes effected by the user
3. That merged State is then stored (and subsequently reloaded) as [Adaptable State](https://www.adaptabletools.com/docs/dev-guide-adaptable-state/index.md)

Learn how Initial State works in greater detail in [Guide to using Adaptable State](https://www.adaptabletools.com/docs/dev-guide-adaptable-state/index.md) and the [Initial State Reference](https://www.adaptabletools.com/docs/dev-guide-adaptable-state-initial-state/index.md)

### Adaptable API

The [Adaptable API](https://www.adaptabletools.com/docs/technical-reference-adaptable-api/index.md) provides full, rich, programmatic, **run-time access** to all AdapTable functionality.

This allows you to access [Adaptable State](https://www.adaptabletools.com/docs/dev-guide-adaptable-state/index.md) in a 'safe' manner.

Anything that is achievable in the AdapTable UI can be accomplised alternatively using the Adaptable API.

- You can even use Adaptable API to connect to AdapTable's functionality via your own custom screens
- This will then allow you to bypass AdapTable's UI altogether

See the full contents of the Adaptable API in [Technical Reference](https://www.adaptabletools.com/docs/technical-reference-adaptable-api/index.md)

### Fitting It Together

These 3 concepts are linked together when AdapTable is [instantiated](https://www.adaptabletools.com/docs/getting-started-integration/index.md).

The first two steps - creating **Adaptable Options** and providing **Initial Adaptable State** - are identical across all four variants of AdapTable.

- The final step differs per framework as each has its own mechanism for creating AdapTable and tying it to AG Grid
- Neverthless each framework's mechanism provides a handle to the same **Adaptable API**.

### Fitting these 3 Key Concepts Together

**Adaptable Options** contains a large group of properties and classes.

It is required by all four framework versions to initialise and configure AdapTable.

```ts {1}
const adaptableOptions: AdaptableOptions = {
  licenseKey: '<ADAPTABLE_LICENSE_KEY_HERE>', // license key you were given
  primaryKey: 'tradeId', // a unique column
  adaptableId: 'trading_app', // a unique grid id
  filterOptions: { clearFiltersOnStartUp: true }, // configurable options
  initialState: initialState, // Inital Adaptable State required
};
```

Adaptable Options includes **Initial Adaptable State** as a mandatory property.

This must include a Layout, and in every real-world use case, additional objects.

```ts {1}
const initialState: InitialState = {
  Dashboard: {
    Tabs: [{ Name: 'Grid', Toolbars: ['Layout', 'Pricing']}],
  },
  Layout: {
    CurrentLayout: 'Cars',
    Layouts: [
      {
        TableColumns: ['Model', 'Price', 'Make'],
        RowGroupedColumns: ['Make'],
        Name: 'Cars',
      },
    ],
  },
} as InitialState;
```

<!-- framework: vanilla -->
### Vanilla

In the **Vanilla** (TypeScript) version, the static async `Adaptable.init` constructor receives the Adaptable Options and an [`AgGridConfig`](https://www.adaptabletools.com/docs/reference/aggridconfig.md) object.

It returns (via a Promise) the **Adaptable API** object which gives full run-time access to all AdapTable functionality.

```ts {6}
const agGridConfig: AgGridConfig = {
  gridOptions,     // AG Grid GridOptions object
  agGridModules,   // AG Grid Modules required
};

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

<!-- /framework -->

<!-- framework: react -->
### React

In **AdapTable React** you render the `Adaptable.Provider` component (passing Adaptable Options, Grid Options and AG Grid Modules).

Obtain the **Adaptable API** from the `adaptableReady` callback, which receives an [`AdaptableReadyInfo`](https://www.adaptabletools.com/docs/reference/adaptablereadyinfo.md) object.

```jsx {5-7}
<Adaptable.Provider
  gridOptions={gridOptions}
  modules={agGridModules}
  adaptableOptions={adaptableOptions}
  adaptableReady={({ adaptableApi }: AdaptableReadyInfo) => {
    // adaptableApi gives full run-time access to AdapTable
  }}
>
  <Adaptable.UI />
  <Adaptable.AgGridReact />
</Adaptable.Provider>
```

<!-- /framework -->

<!-- framework: angular -->
### Angular

In **AdapTable Angular** you render the `<adaptable-provider>` component and bind to its `(adaptableReady)` output.

The handler receives an [`AdaptableReadyInfo`](https://www.adaptabletools.com/docs/reference/adaptablereadyinfo.md) object which contains the **Adaptable API**.

```html {5,15}
<adaptable-provider
  [adaptableOptions]="adaptableOptions"
  [gridOptions]="gridOptions"
  [modules]="agGridModules"
  (adaptableReady)="adaptableReady($event)"
>
  <adaptable-ui></adaptable-ui>
  <ag-grid-angular *adaptable="let adaptable"
    [gridOptions]="adaptable.gridOptions"
    [modules]="adaptable.modules">
  </ag-grid-angular>
</adaptable-provider>

export class AppComponent {
  adaptableReady = ({ adaptableApi }: AdaptableReadyInfo) => {
    // adaptableApi gives full run-time access to AdapTable
  };
}
```

<!-- /framework -->

<!-- framework: vue -->
### Vue

In **AdapTable Vue** you render the `AdaptableProvider` component and listen to its `onAdaptableReady` event.

The event provides an [`AdaptableReadyInfo`](https://www.adaptabletools.com/docs/reference/adaptablereadyinfo.md) object which contains the **Adaptable API**.

```vue {5-9}
<AdaptableProvider
  :gridOptions="gridOptions"
  :modules="agGridModules"
  :adaptableOptions="adaptableOptions"
  @onAdaptableReady="
    ({ adaptableApi }: AdaptableReadyInfo) => {
      // adaptableApi gives full run-time access to AdapTable
    }
  "
>
  <AdaptableUI />
  <AdaptableAgGridVue style="flex: 1" />
</AdaptableProvider>
```

<!-- /framework -->

[Modules](https://www.adaptabletools.com/docs/technical-reference-adaptable-modules/index.md), [Plugins](https://www.adaptabletools.com/docs/technical-reference-plugins/index.md), [Events](https://www.adaptabletools.com/docs/technical-reference-adaptable-events/index.md), [Entitlements](https://www.adaptabletools.com/docs/handbook-permissioning/index.md), [Layouts](https://www.adaptabletools.com/docs/handbook-layouts/index.md), [AdapTableQL](https://www.adaptabletools.com/docs/adaptable-ql-expression/index.md) and [Logging](https://www.adaptabletools.com/docs/dev-guide-support-logging/index.md) each have their own dedicated guides
