#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.
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:
actionsandalertForm— 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,columnTypesordataTypes). No scope means every column.type— the kind of change it watches.'cellChange'is the only type.
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.
#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-editaction, 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}}:
| Placeholder | Resolves 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.
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 components.Notification to the Provider. It receives the
notification (header, message, type, icon), the alert's form already
rendered, and an onClose callback.
#Conditional alerts
A condition is a boolean AdaptableQL expression evaluated against the changed
row. The alert only fires when it's true.
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' }],
},
};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:
| Action | What it does |
|---|---|
highlight-cell | colors the changed cell |
highlight-row | colors the whole row of the changed cell |
jump-to-cell | scrolls the grid so the changed cell is visible |
jump-to-row | scrolls the grid so the changed row is visible |
log-to-console | writes the alert to the Adaptable logger |
prevent-edit | reverts 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' },
],
},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.
#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.
<script setup lang="ts">
import { Adaptable, type AdaptableProps } from '@adaptabletools/datagrid-vue';
declare const props: AdaptableProps;
const events: AdaptableProps['events'] = {
onAlertTrigger: ({ alert }) => {
console.log('alert triggered', alert.header, alert.message);
},
};
</script>
<template>
<Adaptable.Provider v-bind="props" :events="events">
<Adaptable.UI />
</Adaptable.Provider>
</template>To see every data change, not only the ones that match an alert, use
events.onDataChanges — it receives the changes array.
The alert has no notification. Edit a few cells — every alert that fires is
listed above the grid by the onAlertTrigger listener.
#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.UI.AlertsManager (needs
only an Adaptable.Provider ancestor):
<Adaptable.Provider v-bind="props">
<Adaptable.UI />
<Adaptable.UI.AlertsManager />
</Adaptable.Provider>For fully custom UIs, the useAlerts composable exposes the same operations.
It returns a ref of an object with them:
import { useAlerts } from '@adaptabletools/datagrid-vue';
// in the setup of a component rendered inside the provider
const alertsRef = useAlerts();
function onToolbarAction() {
// read `.value` when you need it (the template unwraps the ref)
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
} = alertsRef.value;
// ...
}Imperatively, adaptableApi.alertApi offers createAlert, editAlert,
deleteAlert and getAllAlerts.