Adaptable

#Alerts

Alerts watch the grid's data for changes and react when a change matches: they show a notification, run grid actions (highlight, jump to, undo) and fire an event you can listen to.

Alerts are defined in the Adaptable state under alert, keyed by id. Unlike styled cells, alerts are global — they watch every view of the Adaptable instance.

Two alerts
const state: AdaptableUserState = {
  alert: {
    alerts: {
      'any-change': {
        label: 'Any change',
        type: 'cellChange',
        notification: { display: true, duration: 3000 },
      },
      'salary-change': {
        label: 'Salary change',
        type: 'cellChange',
        scope: { columns: ['salary'] },
        message: { type: 'success', header: 'Salary updated' },
        notification: { display: true, duration: 3000 },
      },
    },
  },
  view: {
    currentViewId: 'default',
    views: [{ id: 'default', label: 'Default' }],
  },
};

An alert has:

  • actions and alertForm — what the alert does, and the buttons its notification offers (see Actions).
  • condition — an optional AdaptableQL expression the changed row must satisfy (see Conditional alerts).
  • label — the name shown in the settings panel.
  • message — the header, text and type of the alert.
  • notification — whether (and for how long) a toast is shown.
  • scope — which columns it watches (columns, columnTypes or dataTypes). No scope means every column.
  • type — the kind of change it watches. 'cellChange' is the only type.
#
Alerts on cell changes

Double-click a cell to edit it. Every edit triggers the Any change alert; editing a salary also triggers Salary change, so you get two notifications.

open
loading demo…

#What triggers an alert

Alerts react to changes in the data source: cell edits made in the grid and updates made through the API, such as adaptableApi.dataSourceApi.updateData(...) or insertData(...). A change triggers an alert when the changed column is in the alert's scope and, if the alert has a condition, the row satisfies it.

Some changes never trigger alerts:

  • deleted rows,
  • a value written back unchanged,
  • changes made by undoing an edit (the prevent-edit action, below).

#Messages

message.type is one of success, info, warning or error (the default). It sets the color of the notification and of the highlight-cell / highlight-row actions.

message.header and message.text accept a string with {{placeholders}}:

PlaceholderResolves to
{{column}}name of the changed column
{{columnId}}id of the changed column
{{oldValue}}value before the change
{{newValue}}value after the change
{{primaryKey}}primary key of the changed row
{{alert}}the alert's label
{{scope}}the columns the alert applies to
{{condition}}the condition expression
{{row.<field>}}any field of the changed row, e.g. {{row.firstName}}

Unknown placeholders stay in the output as typed, so a typo is visible.

For full control, pass a function instead. It receives a context with dataChange (the change that fired the alert) and adaptableApi:

message: {
  header: 'Salary updated',
  text: ({ dataChange }) =>
    dataChange?.type === 'update' ? `New salary: ${dataChange.newValue}` : 'Salary changed',
},

Without a header, the notification shows the message type (e.g. "Warning") or, when no type is set either, the name of the changed column. Without a text, it shows the scope and the condition of the alert.

#Notifications

notification.display: true shows a toast when the alert fires. notification.duration closes it after that many milliseconds; without a duration the toast stays until the user closes it. notification.icon picks the toast icon.

Note

An alert without notification.display does not show a toast — it still runs its actions and fires the onAlertTrigger event.

To render notifications with your own component — or forward them to your app's toaster — pass it as components.Notification in the Provider's [components] input. It gets three inputs: notification (header, message, type, icon), the alert's form already rendered (show it with <ng-container [infiniteRender]="form()" />), and onClose, a function that removes the notification.

#Conditional alerts

A condition is a boolean AdaptableQL expression evaluated against the changed row. The alert only fires when it's true.

Alert when a salary goes over 150k
const conditionalState: AdaptableUserState = {
  alert: {
    alerts: {
      'high-salary': {
        label: 'Salary over 150k',
        type: 'cellChange',
        scope: { columns: ['salary'] },
        condition: { expression: '[salary] > 150000' },
        message: { type: 'warning', header: 'High salary' },
        notification: { display: true },
      },
    },
  },
  view: {
    currentViewId: 'default',
    views: [{ id: 'default', label: 'Default' }],
  },
};
Note

The scope matters here too. Without it, the alert would fire for a change in any column of a row whose salary is over 150000.

See AdaptableQL for the expression syntax.

#Actions

actions run every time the alert fires. The built-in ones are:

ActionWhat it does
highlight-cellcolors the changed cell
highlight-rowcolors the whole row of the changed cell
jump-to-cellscrolls the grid so the changed cell is visible
jump-to-rowscrolls the grid so the changed row is visible
log-to-consolewrites the alert to the Adaptable logger
prevent-editreverts the change that triggered the alert

The highlights take the color of the message type and last alert.defaultHighlightDuration milliseconds (600 by default). Pass { id: 'highlight-cell', style: { background: 'gold' } } to use your own style.

alertForm.buttons adds buttons to the notification. Each button has a label, optional actions to run when clicked, and an optional onClick. Clicking a button closes the notification.

alertForm: {
  buttons: [
    { label: 'Undo', actions: ['prevent-edit'] },
    { label: 'Keep' },
  ],
},
#
A conditional alert with actions

Set a salary above 150000. The row is highlighted for two seconds and a warning asks whether to keep the change — Undo reverts it. Salaries at or below 150000 don't trigger the alert.

open
loading demo…

#Custom actions

Register your own actions in alert.customActions and reference them by id in actions or in a button's actions. Each receives the alert context (dataChange and adaptableApi):

const customActionsState: AdaptableUserState = {
  alert: {
    customActions: {
      notifyDesk: {
        label: 'Notify the desk',
        action: ({ dataChange }) => sendToDesk(dataChange),
      },
    },
    alerts: {
      'high-salary': {
        label: 'Salary over 150k',
        type: 'cellChange',
        scope: { columns: ['salary'] },
        condition: { expression: '[salary] > 150000' },
        actions: ['notifyDesk'],
      },
    },
  },
  view: {
    currentViewId: 'default',
    views: [{ id: 'default', label: 'Default' }],
  },
};

#Listening to alerts

Pass events.onAlertTrigger to the Provider to run your own code whenever an alert fires — with or without a notification. It receives the triggered alert: its header, message, messageType and the dataChange that caused it.

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

declare const data: { id: number }[];
declare const defaultState: AdaptableUserState;

@Component({
  selector: 'app-grid',
  imports: [AdaptableProvider, AdaptableUI],
  template: `
    <adaptable-provider
      adaptableId="my-grid"
      primaryKey="id"
      [data]="data"
      [defaultState]="defaultState"
      [events]="events"
    >
      <adaptable-ui />
    </adaptable-provider>
  `,
})
export class AppGrid {
  protected readonly data = data;
  protected readonly defaultState = defaultState;

  protected readonly events: AdaptableProps['events'] = {
    onAlertTrigger: ({ alert }) => {
      console.log('alert triggered', alert.header, alert.message);
    },
  };
}

To see every data change, not only the ones that match an alert, use events.onDataChanges — it receives the changes array.

#
Listening to alerts

The alert has no notification. Edit a few cells — every alert that fires is listed above the grid by the onAlertTrigger listener.

open
loading demo…

#Managing alerts in the UI

The settings panel has an Alerts page where users create, edit and delete alerts, with a step-by-step editor for the scope, condition, message, notification and actions. The alert dashboard widget opens that page.

The page is also available standalone as <adaptable-alerts-manager> (the AlertsManager class; needs only an <adaptable-provider> ancestor):

<adaptable-provider
  adaptableId="my-grid"
  primaryKey="id"
  [data]="data"
  [defaultState]="defaultState"
>
  <adaptable-ui />
  <adaptable-alerts-manager />
</adaptable-provider>

For fully custom UIs, the injectAlerts() function (the Angular counterpart of the useAlerts hook) exposes the same operations. Call it in a component rendered inside <adaptable-provider>; it returns a signal of an object with them:

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

@Component({
  selector: 'my-alerts-toolbar',
  template: `<!-- ... -->`,
})
export class MyAlertsToolbar {
  // in a component rendered inside <adaptable-provider>
  private readonly alertsModel = injectAlerts();

  onToolbarAction() {
    // a signal: read it when you need it, so it is always current
    const {
      alerts, // all alerts defined in state, with their ids
      customActions, // alert.customActions, by id
      createAlert, // (config) => id
      updateAlert, // (id, config) => void
      deleteAlert, // (id) => void
    } = this.alertsModel();

    // ...
  }
}

Imperatively, adaptableApi.alertApi offers createAlert, editAlert, deleteAlert and getAllAlerts.