Adaptable

#injectAdaptableApi

injectAdaptableApi() (the Angular counterpart of the useAdaptableApi hook) returns a signal of the AdaptableApi of the enclosing <adaptable-provider>. Use it in any component rendered inside the provider to act on the grid imperatively — switch views, set the quick search text, change the theme, add or update rows, and so on.

Call it in an injection context — a field initializer or the constructor — of a component written inside <adaptable-provider>. The API exists once the provider is set up: read the signal from ngOnInit on — in the template, an event handler or an effect — and call api() to get the API object. It does not change after that.

Calling the API from a component
import {
  AdaptableProvider,
  AdaptableUI,
  Button,
  injectAdaptableApi,
} from '@adaptabletools/datagrid-angular';

@Component({
  selector: 'demo-toolbar',
  imports: [Button],
  template: `
    <div class="flex flex-row gap-2 p-2">
      <button adaptableButton tone="accent" (click)="api().viewApi.setActiveView('by-salary')">
        By salary
      </button>
      <button adaptableButton tone="accent" (click)="api().viewApi.setActiveView('all')">
        All developers
      </button>
      <button adaptableButton tone="neutral" (click)="api().themeApi.setTheme('dark')">
        Dark theme
      </button>
      <button adaptableButton tone="neutral" (click)="api().themeApi.setTheme('light')">
        Light theme
      </button>
    </div>
  `,
})
class Toolbar {
  protected readonly api = injectAdaptableApi();
}

@Component({
  selector: 'demo-root',
  imports: [AdaptableProvider, AdaptableUI, Toolbar],
  template: `
    <adaptable-provider
      adaptableId="docs-hooks-use-adaptable-api"
      primaryKey="id"
      [data]="data"
      [defaultState]="defaultState"
    >
      <demo-toolbar />
      <adaptable-ui />
    </adaptable-provider>
  `,
})
export default class App {
  protected readonly data = data;
  protected readonly defaultState = defaultState;
}

The API is grouped by feature: viewApi, quickSearchApi, themeApi, dataSourceApi, filterApi, styledCellsApi, alertApi, exportApi, settingsPanelApi, stateApi and more. Pass your row type to get typed data access: injectAdaptableApi<Developer>().

Note

The API object itself does not change and is not reactive: a template or a computed that reads from it is not updated when the state changes. To read state reactively, combine it with injectAdaptableState or one of the feature inject functions.

Outside of a component inside the provider, get the same object from the (ready) output of <adaptable-provider>:

import { Component } from '@angular/core';
import {
  AdaptableProvider,
  AdaptableUI,
  type AdaptableReadyContext,
} from '@adaptabletools/datagrid-angular';

@Component({
  selector: 'app-root',
  imports: [AdaptableProvider, AdaptableUI],
  template: `
    <adaptable-provider
      adaptableId="app"
      primaryKey="id"
      [data]="data"
      [defaultState]="defaultState"
      (ready)="onReady($event)"
    >
      <adaptable-ui />
    </adaptable-provider>
  `,
})
export class App {
  protected readonly data = data;
  protected readonly defaultState = defaultState;

  protected onReady({ adaptableApi }: AdaptableReadyContext) {
    adaptableApi.quickSearchApi.setSearchText('Python');
  }
}
#
Driving the grid with useAdaptableApi

The buttons call api().viewApi.setActiveView and api().quickSearchApi.setSearchText. The label next to them reads the current view with injectCurrentViewState, so it updates as you switch views.

open
loading demo…