Monitoring Layout Changes

View as Markdown

Summary

  • The Layout Changed Event fires whenever Layout State changes
  • actionName says what triggered the change
  • changedAreas says which parts of the current Layout changed

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.

PropertyTypeDescription
actionNameLayoutChangedActionWhich action caused this change. See .
changedAreasLayoutChangedArea[]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).
newLayoutStateLayoutStateLayout State after this change.
oldLayoutStateLayoutState | undefinedLayout State before this change.

Absent for LAYOUT_READY, which fires once after startup and has no previous state.
adaptableContextanyCustom 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:

ActionDescription
LAYOUT_READYFired once after AdapTable starts, for the Layout that is already current
LAYOUT_ADDA Layout has been added
LAYOUT_EDITA Layout has been edited
LAYOUT_SAVEA Layout has been saved, including auto-save after grid edits (sort, grouping, columns, and so on)
LAYOUT_DELETEA Layout has been deleted
LAYOUT_SELECTA different Layout has been selected
LAYOUT_COLUMN_FILTER_ADDA Column Filter has been added
LAYOUT_COLUMN_FILTER_EDITA Column Filter has been edited
LAYOUT_COLUMN_FILTER_SETColumn Filters have been set
LAYOUT_COLUMN_FILTER_CLEARA Column Filter has been cleared
LAYOUT_COLUMN_FILTER_CLEAR_ALLAll Column Filters have been cleared
LAYOUT_COLUMN_FILTER_SUSPENDA Column Filter has been suspended
LAYOUT_COLUMN_FILTER_SUSPEND_ALLAll Column Filters have been suspended
LAYOUT_COLUMN_FILTER_UNSUSPENDA Column Filter has been unsuspended
LAYOUT_COLUMN_FILTER_UNSUSPEND_ALLAll Column Filters have been unsuspended
LAYOUT_GRID_FILTER_SETThe Grid Filter has been set
LAYOUT_GRID_FILTER_CLEARThe Grid Filter has been cleared
LAYOUT_GRID_FILTER_SUSPENDThe Grid Filter has been suspended
LAYOUT_GRID_FILTER_UNSUSPENDThe 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_DELETE and LAYOUT_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:

AreaDescription
ColumnsVisible columns or column order changed
ColumnPinningColumn pinning changed
ColumnHeadersColumn captions (or suppress agg func in header) changed
ColumnSortingColumn sorts changed
RowGroupingRow grouping (table or pivot) changed
AggregationsTable or pivot aggregations changed
RowSummariesRow summaries changed
RowSelectionLayout row-selection settings changed
ColumnFilterA Column Filter action fired
GridFilterA Grid Filter action fired
PivotingPivot columns, expand level or pivot totals changed
Layout Changed
Fork
  • This demo listens to the Layout Changed Event and outputs a System Status Message with the actionName and any changedAreas
Try It Out
  • 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 matching changedAreas
Loading demo…