# Data Change History Buttons

Canonical page: https://www.adaptabletools.com/docs/handbook-monitoring-data-change-history-buttons

- Buttons can be added to Data Change History Monitor

The `changeHistoryButton` property in [Data Change History Options](https://www.adaptabletools.com/docs/technical-reference-monitoring-data-change-history/index.md) allows developers to provide custom button(s) on each row of the Data Changes Monitor.

When buttons are configured, AdapTable adds an [Action Column](https://www.adaptabletools.com/docs/handbook-action-column/index.md) in the monitor grid

You can wire buttons for undo, clear, or fully custom behaviour.

### `changeHistoryButton`

Action Button to display in each row in Data Changes Monitor - can implement undo functionality

  [`DataChangeHistoryButton`](https://www.adaptabletools.com/docs/reference/datachangehistorybutton.md)

Definition of a button (or buttons) on each row in the Data Changes Monitor.

It is most commonly used for undo (set `action: 'undo'`).

When `action` is `'undo'` or `'clear'`, AdapTable runs the built-in behaviour; you do not need an `onClick` handler

Each button receives [`DataChangeHistoryContext`](https://www.adaptabletools.com/docs/reference/datachangehistorycontext.md) (extends action-column context) with:

- `dataChangedInfo` — the [`CellDataChangedInfo`](https://www.adaptabletools.com/docs/reference/celldatachangedinfo.md) for the row
- `undoDataChange()` — revert the underlying grid cell
- `clearRow()` — remove the row from the monitor log
- `isGroupNode` — whether the row represents a grouped change
- `parentAdapTableApi` — API for the main grid (not the monitor)

```ts
const adaptableOptions: AdaptableOptions = {
  dataChangeHistoryOptions: {
    changeHistoryButton: [
      {
        action: 'undo',
        label: 'Undo',
        buttonStyle: {
          variant: 'raised',
          tone: 'accent',
        },
      },
    ],
  },
};
```

Custom behaviour uses `onClick`:

```ts
const adaptableOptions: AdaptableOptions = {
  dataChangeHistoryOptions: {
    changeHistoryButton: [
      {
        label: "Publish to Support",
        onClick: (button, context) => {
          // e.g. send context.dataChangedInfo to support
        },
        buttonStyle: {
          variant: 'raised',
          tone: 'accent',
        },
      },
    ],
  },
};
```

### Button Actions

Data Change History buttons often perform one of two actions:

- **Undo** — revert the data change shown on the row
- **Clear** — remove the row from the monitor so it is no longer visible (grid data unchanged)

AdapTable provides built-in `action` values `'undo'` and `'clear'`.

**Example: Data Change History: Button Actions**

Using Undo and Clear Actions in Data Change History

- Two buttons in `adaptableOptions.ts`: `action: 'undo'` and `action: 'clear'`
- Undo uses a dynamic label for group rows (*Undo Group* vs *Undo*)

- Make an edit, open the monitor, and try **Undo** and **Clear**

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Data Change History Action Buttons',
  dataChangeHistoryOptions: {
    activeByDefault: true,
    changeHistoryButton: [
      {
        action: 'undo',
        label: (button, context) => {
          return context.isGroupNode ? 'Undo Group' : 'Undo';
        },
        buttonStyle: {
          variant: 'raised',
          tone: 'accent',
        },
      },
      {
        action: 'clear',
        label: 'Clear',
        buttonStyle: {
          variant: 'outlined',
          tone: 'neutral',
        },
      },
    ],
  },
  initialState: {
    Dashboard: {
      Tabs: [
        {
          Name: 'Data Change',
          Toolbars: ['DataChangeHistory'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    FormatColumn: {
      FormatColumns: [
        {
          Name: 'formatColumn-updated_at',
          Scope: {
            ColumnIds: ['updated_at'],
          },
          DisplayFormat: {
            Formatter: 'DateFormatter',
            Options: {
              Pattern: 'HH:mm:ss',
            },
          },
        },
      ],
    },
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'github_stars',
            'language',
            'github_watchers',
            'updated_at',
            'description',
            'created_at',
            'has_wiki',
            'pushed_at',
            'open_issues_count',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

## Undo Button

Alternatively, use a custom `onClick` and call the context helpers yourself.

For example, you might notify a backend before undoing, or highlight the affected cell on the main grid before calling `context.undoDataChange()`.

- You do not need to implement undo logic
- `undoDataChange()` and `clearRow()` on [`DataChangeHistoryContext`](https://www.adaptabletools.com/docs/reference/datachangehistorycontext.md) delegate to AdapTable

**Example: Data Change History: Undo Button**

Extending Data Change history with Undo Buttons

- Single custom button in `adaptableOptions.ts` that calls `context.undoDataChange()` from `onClick`

- Edit a cell, open the monitor, and use **Undo**

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {CellHighlightInfo} from '@adaptabletools/adaptable';
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Data Change History Undo Button',
  dataChangeHistoryOptions: {
    activeByDefault: true,
    changeHistoryButton: [
      {
        label: (button, context) => {
          return context.isGroupNode ? 'Undo Group' : 'Undo';
        },
        onClick: (button, context) => {
          context.undoDataChange();
        },
        buttonStyle: {
          variant: 'raised',
          tone: 'accent',
        },
      },
      {
        label: (button, context) => {
          return 'Highlight';
        },
        onClick: (button, context) => {
          if (context.isGroupNode) {
            return;
          }

          const cellHighlightInfo: CellHighlightInfo = {
            columnId: context.dataChangedInfo.column.columnId,
            primaryKeyValue: context.dataChangedInfo.primaryKeyValue,
            timeout: 3000,
            highlightStyle: {
              BackColor: 'var(--ab-color-palette-21)',
            },
          };
          context.parentAdapTableApi.gridApi.highlightCell(cellHighlightInfo);
        },
        buttonStyle: {
          variant: 'raised',
          tone: 'info',
        },
      },
    ],
  },
  initialState: {
    Dashboard: {
      Tabs: [
        {
          Name: 'Data Change',
          Toolbars: ['DataChangeHistory'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    FormatColumn: {
      FormatColumns: [
        {
          Name: 'formatColumn-updated_at',
          Scope: {
            ColumnIds: ['updated_at'],
          },
          DisplayFormat: {
            Formatter: 'DateFormatter',
            Options: {
              Pattern: 'HH:mm:ss',
            },
          },
        },
      ],
    },
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'github_stars',
            'language',
            'github_watchers',
            'updated_at',
            'description',
            'created_at',
            'has_wiki',
            'pushed_at',
            'open_issues_count',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```
