Adaptable

#injectAdaptableState

injectAdaptableState() (the Angular counterpart of the useAdaptableState hook) gives you a signal of the Adaptable state — or of a part of it — in any component rendered inside <adaptable-provider>. Call it in an injection context (a field initializer or the constructor). The signal follows the state: a template, a computed or an effect that reads it is updated when the value changes.

import { injectAdaptableState } from '@adaptabletools/datagrid-angular';
Note

To run code when the state changes (logging, syncing to a server), use injectAdaptableStateSubscribe: its callback also gets the previous value and the Adaptable API.

#Usage

Call it without arguments to get the whole state:

protected readonly adaptableState = injectAdaptableState();

Or pass a selector function to pick the part you are interested in:

Getting the id of the active view
protected readonly currentViewId = injectAdaptableState((state) => state.view.currentViewId);
Getting the applied theme
protected readonly theme = injectAdaptableState((state) => state.theme.currentTheme);

What you get is a read-only Signal. Call it to read the value, in the template and in the class.

Reading the signals
@Component({
  selector: 'current-view-summary',
  template: `
    <!-- in the template, call the signal -->
    <div>Current view: {{ currentViewId() }}</div>
    <div>{{ summary() }}</div>
  `,
})
export class CurrentViewSummary {
  protected readonly currentViewId = injectAdaptableState((state) => state.view.currentViewId);
  protected readonly theme = injectAdaptableState((state) => state.theme.currentTheme);

  // in the class too: a computed follows both signals
  protected readonly summary = computed(() => `${this.currentViewId()} (${this.theme()} theme)`);
}

Prefer a selector: without one, the signal gets a new value on every state change, and everything that reads it is updated. The selector receives the full AdaptableState; the slices are described in the state reference. To combine the result with your own signals, use a computed that reads the returned signal.

For common reads, the dedicated inject functions are shorter — injectCurrentViewState for the active view, or the feature inject functions (injectViews, injectTheme, …), which also return the setters.

#
Reading the state with useAdaptableState

The current view is read from the state in two places: the line above the grid (view label and theme) and the header of the First name column (view id), rendered through the column's renderHeader.

Switch the view from the dashboard to see both update.

open
loading demo…