Monitoring Layout Changes
Summary
- The Layout Changed Event fires whenever Layout State changes
actionNamesays what triggered the changechangedAreassays which parts of the current Layout changed
Find Out More
AdapTable fires a Layout Changed Event whenever Layout State changes.
Find Out More
LayoutChangedInfo, the action names and the changed areas are also listed in the Layout Technical Reference
The Event Info is a single LayoutChangedInfo object.
It includes the previous and current Layout State, plus:
actionName— why the Event fired (a Layout was selected, saved, filtered, and so on)changedAreas— what on the current Layout actually changed (when the Layout is edited in place)
Listening to the Event
Subscribe to the Event the same way as with any other Adaptable Event.
Hint
A common way to use the Event is to check the actionName, and then make any changes using Layout API
// This example ensures every Layout has a Grand Total Row at the top.
// `LAYOUT_SELECT` fires when the user switches Layout;
// `LAYOUT_READY` fires once after AdapTable starts, for the Layout that is already current:
api.eventApi.on('LayoutChanged', (eventInfo: LayoutChangedInfo) => {
if (
eventInfo.actionName !== 'LAYOUT_SELECT' &&
eventInfo.actionName !== 'LAYOUT_READY'
) {
return;
}
const layout = api.layoutApi.getCurrentLayout();
if (layout.GrandTotalRow === 'top') {
return;
}
api.layoutApi.updateCurrentLayout(current => ({
...current,
GrandTotalRow: 'top',
}));
});Layout Changed Info
The LayoutChangedInfo object which is provided by the Layout is defined as follows:
Payload of the LayoutChanged event.
Fires when Layout State changes: the current Layout is ready, added, edited, saved, deleted or selected, and when a Column Filter or the Grid Filter on the current Layout changes.
Extends , so adaptableApi is included.
| Property | Type | Description |
|---|---|---|
| actionName | LayoutChangedAction | Which action caused this change. See . |
| changedAreas | LayoutChangedArea[] | Which parts of the current Layout changed. Use this when you care what changed, rather than which actionName fired:- LAYOUT_SAVE: diffs non-filter facets (e.g. ColumnSorting, RowGrouping)- Column Filter actions: always ['ColumnFilter']- Grid Filter actions: always ['GridFilter']Omitted for layout identity changes ( LAYOUT_SELECT, LAYOUT_ADD, LAYOUT_DELETE, LAYOUT_READY). |
| newLayoutState | LayoutState | Layout State after this change. |
| oldLayoutState | LayoutState | undefined | Layout State before this change. Absent for LAYOUT_READY, which fires once after startup and has no previous state. |
| adaptableContext | any | Custom application Context provided in AdaptableOptions.adaptableContext |
Layout Actions
Every Layout Changed Event includes an Action, which describes what caused the Layout to change.
This is provided using the actionName property which is of type LayoutChangedAction.
These are the Actions which can cause the Layout Changed Event to trigger:
| Action | Description |
|---|---|
LAYOUT_READY | Fired once after AdapTable starts, for the Layout that is already current |
LAYOUT_ADD | A Layout has been added |
LAYOUT_EDIT | A Layout has been edited |
LAYOUT_SAVE | A Layout has been saved, including auto-save after grid edits (sort, grouping, columns, and so on) |
LAYOUT_DELETE | A Layout has been deleted |
LAYOUT_SELECT | A different Layout has been selected |
LAYOUT_COLUMN_FILTER_ADD | A Column Filter has been added |
LAYOUT_COLUMN_FILTER_EDIT | A Column Filter has been edited |
LAYOUT_COLUMN_FILTER_SET | Column Filters have been set |
LAYOUT_COLUMN_FILTER_CLEAR | A Column Filter has been cleared |
LAYOUT_COLUMN_FILTER_CLEAR_ALL | All Column Filters have been cleared |
LAYOUT_COLUMN_FILTER_SUSPEND | A Column Filter has been suspended |
LAYOUT_COLUMN_FILTER_SUSPEND_ALL | All Column Filters have been suspended |
LAYOUT_COLUMN_FILTER_UNSUSPEND | A Column Filter has been unsuspended |
LAYOUT_COLUMN_FILTER_UNSUSPEND_ALL | All Column Filters have been unsuspended |
LAYOUT_GRID_FILTER_SET | The Grid Filter has been set |
LAYOUT_GRID_FILTER_CLEAR | The Grid Filter has been cleared |
LAYOUT_GRID_FILTER_SUSPEND | The Grid Filter has been suspended |
LAYOUT_GRID_FILTER_UNSUSPEND | The Grid Filter has been unsuspended |
Layout Changed Areas
changedAreas is for when you care which part of the current Layout changed, without enumerating every filter actionName or deep-diffing Layout State yourself.
It is only set when the current Layout is edited in place:
LAYOUT_SAVE— AdapTable diffs the previous and next Layout and lists the facets that actually changed (sort, grouping, columns, and so on)- any Column Filter action — always
['ColumnFilter'] - any Grid Filter action — always
['GridFilter']
Caution
- It is omitted for Layout identity changes:
LAYOUT_SELECT,LAYOUT_ADD,LAYOUT_DELETEandLAYOUT_READY - Those change which Layout is current (or that a Layout exists), not a facet of the current one
api.eventApi.on('LayoutChanged', (eventInfo: LayoutChangedInfo) => {
if (eventInfo.changedAreas?.includes('ColumnSorting')) {
// sort changed on the current Layout (via LAYOUT_SAVE)
}
if (eventInfo.changedAreas?.includes('ColumnFilter')) {
// any Column Filter action (set, clear, suspend, and so on)
}
});Note
Column sizing is not included because AG Grid often reports incidental width or flex changes on unrelated edits
The possible values are of type LayoutChangedArea:
| Area | Description |
|---|---|
Columns | Visible columns or column order changed |
ColumnPinning | Column pinning changed |
ColumnHeaders | Column captions (or suppress agg func in header) changed |
ColumnSorting | Column sorts changed |
RowGrouping | Row grouping (table or pivot) changed |
Aggregations | Table or pivot aggregations changed |
RowSummaries | Row summaries changed |
RowSelection | Layout row-selection settings changed |
ColumnFilter | A Column Filter action fired |
GridFilter | A Grid Filter action fired |
Pivoting | Pivot columns, expand level or pivot totals changed |
- This demo listens to the Layout Changed Event and outputs a System Status Message with the
actionNameand anychangedAreas
- Switch Layout in the Layout toolbar and note
LAYOUT_SELECT - Sort or filter a column and note
LAYOUT_SAVE/ Column Filter actions, together with the matchingchangedAreas