
Batch editing with three-way conflict review
Compare the original, draft and authoritative server values before retrying a rejected batch.

A toolbar outside a data grid needs more than a reference to the grid. Its Undo button should disable when history is empty or replaying, its Redo button should follow changes caused by keyboard shortcuts, and its actions must target the correct grid when an application renders two independent tables.
The solution is to scope the connection to one grid, read the plugin's actual state, subscribe to state changes and dispose subscriptions when the grid instance changes. RevoGrid Pro v4.4.3 exposes framework-native providers and accessors for that pattern in React, Vue and Angular.
We'll build custom history buttons in all three frameworks using the same small TypeScript adapter. You can apply the pattern to filtering, export and other plugin controls, but each plugin has its own state contract.
A local counter that increments on each edit is not history state. History can combine multiple edits, reject a replay, reset on source replacement, or be changed through built-in keyboard commands.
| Problem | Consequence of a naive toolbar |
|---|---|
| Two grids on the page | A global query or shared ref invokes the wrong grid |
| Grid unmounted during navigation | An old event listener or action retains a destroyed grid |
| Shortcut changes history | Toolbar's local counter becomes stale |
| Asynchronous grid discovery | A late response can bind controls to a previous instance |
| Plugin absent or replay pending | A button remains enabled even though its action is unavailable |
The plugin is the owner of the command state. The toolbar renders a snapshot of that state and delegates the action back to the plugin.
Install the Pro package and the framework wrapper. The provider discovers one grid in its scope. The accessors expose that grid once it is ready, and clear the connection when it is removed or replaced.
The adapter below reads HistoryPlugin.canUndo() and canRedo(), which account for disabled history and pending replay. It listens to historychanged and checks the current plugin again rather than maintaining a second history counter.
// history-toolbar.ts
import { HistoryPlugin } from '@revolist/revogrid-pro';
export type HistoryButtons = {
grid: HTMLRevoGridElement | null;
canUndo: boolean;
canRedo: boolean;
undo(): void;
redo(): void;
};
export const disconnected: HistoryButtons = {
grid: null, canUndo: false, canRedo: false,
undo() {}, redo() {},
};
export function watchHistory(
grid: HTMLRevoGridElement | null,
publish: (state: HistoryButtons) => void,
): () => void {
publish(disconnected);
if (!grid) return () => {};
let active = true;
let revision = 0;
let history: HistoryPlugin | undefined;
async function refresh() {
const current = ++revision;
try {
const plugins = await grid!.getPlugins();
if (!active || current !== revision) return;
history = plugins.find(p => p instanceof HistoryPlugin);
publish({
grid,
canUndo: history?.canUndo() ?? false,
canRedo: history?.canRedo() ?? false,
undo() { if (active && history?.canUndo()) history.undo(); },
redo() { if (active && history?.canRedo()) history.redo(); },
});
} catch (error) {
if (active && current === revision) {
history = undefined;
publish(disconnected);
console.error('History control connection failed', error);
}
}
}
const onChange = () => { void refresh(); };
grid.addEventListener('historychanged', onChange);
grid.addEventListener('historyerror', onChange);
void refresh();
return () => {
active = false;
history = undefined;
revision++;
grid.removeEventListener('historychanged', onChange);
grid.removeEventListener('historyerror', onChange);
};
}The revision guard handles a late getPlugins() result. Cleanup disables old action closures, removes listeners, and prevents asynchronous reads from publishing into an unmounted control. The action checks the plugin's current capability again when the button is clicked.
Configure history on the grid as usual. This adapter does not replace HistoryPlugin or implement its own undo stack.
import { useEffect, useState } from 'react';
import { RevoGrid } from '@revolist/react-datagrid';
import { HistoryPlugin } from '@revolist/revogrid-pro';
import {
GridControlsProvider,
useGridControls,
} from '@revolist/revogrid-pro/react';
import { disconnected, watchHistory } from './history-toolbar';
import '@revolist/revogrid-pro/styles.css';
function CustomToolbar() {
const grid = useGridControls();
const [state, setState] = useState(disconnected);
useEffect(() => watchHistory(grid, setState), [grid]);
const connected = !!grid && state.grid === grid;
return (
<div role="group" aria-label="Edit history">
<button disabled={!connected || !state.canUndo}
onClick={state.undo}>Undo</button>
<button disabled={!connected || !state.canRedo}
onClick={state.redo}>Redo</button>
</div>
);
}
const plugins = [HistoryPlugin];
const columns = [{ prop: 'name', name: 'Name' }];
function TeamGrid({ name }: { name: string }) {
const [rows] = useState(() => [{ name }]);
return (
<GridControlsProvider>
<CustomToolbar />
<RevoGrid style={{ height: 240 }}
source={rows} columns={columns} plugins={plugins} />
</GridControlsProvider>
);
}
export function TwoGrids() {
return (
<>
<TeamGrid name="Design" />
<TeamGrid name="Engineering" />
</>
);
}The two providers isolate the histories. An edit in Design must not enable the Engineering Undo button. The comparison between the current grid and the snapshot's grid also prevents stale buttons from activating during a React instance replacement.
useGridControls() returns a readonly ref in Vue. A watcher can connect the same adapter and register cleanup for both replacement and component destruction.
<!-- CustomToolbar.vue -->
<script setup lang="ts">
import { shallowRef, watch } from 'vue';
import { useGridControls } from '@revolist/revogrid-pro/vue';
import { disconnected, watchHistory } from './history-toolbar';
const grid = useGridControls();
const state = shallowRef(disconnected);
watch(grid, (current, _previous, onCleanup) => {
onCleanup(watchHistory(current, next => { state.value = next; }));
}, { immediate: true });
</script>
<template>
<div role="group" aria-label="Edit history">
<button :disabled="!grid || state.grid !== grid || !state.canUndo"
@click="state.undo()">Undo</button>
<button :disabled="!grid || state.grid !== grid || !state.canRedo"
@click="state.redo()">Redo</button>
</div>
</template>Mount it with its grid:
<script setup lang="ts">
import { VGrid } from '@revolist/vue3-datagrid';
import { HistoryPlugin } from '@revolist/revogrid-pro';
import { GridControlsProvider } from '@revolist/revogrid-pro/vue';
import CustomToolbar from './CustomToolbar.vue';
import '@revolist/revogrid-pro/styles.css';
const plugins = [HistoryPlugin];
const columns = [{ prop: 'name', name: 'Name' }];
const rows = [{ name: 'Design' }, { name: 'Engineering' }];
</script>
<template>
<GridControlsProvider>
<CustomToolbar />
<VGrid style="height: 240px" :plugins="plugins"
:columns="columns" :source="rows" />
</GridControlsProvider>
</template>Angular uses GridControlsScope and its subscribe method. The provider discovers the projected grid, and the custom standalone component can inject the scope. The Pro Angular framework entry in this release requires Angular 22.2 or newer.
import { Component, inject, OnDestroy, signal } from '@angular/core';
import { GridControlsScope } from '@revolist/revogrid-pro/angular';
import { disconnected, watchHistory } from './history-toolbar';
@Component({
selector: 'custom-toolbar',
standalone: true,
template: `
<div role="group" aria-label="Edit history">
<button [disabled]="!state().canUndo"
(click)="state().undo()">Undo</button>
<button [disabled]="!state().canRedo"
(click)="state().redo()">Redo</button>
</div>
`,
})
export class CustomToolbar implements OnDestroy {
private readonly scope = inject(GridControlsScope);
readonly state = signal(disconnected);
private disconnect = () => {};
private current: HTMLRevoGridElement | null = null;
private connect = () => {
const grid = this.scope.grid;
if (grid === this.current) return;
this.disconnect();
this.current = grid;
this.disconnect = watchHistory(grid, value => this.state.set(value));
};
private readonly unsubscribe = this.scope.subscribe(this.connect);
constructor() { this.connect(); }
ngOnDestroy() {
this.unsubscribe();
this.disconnect();
}
}Place the component and the grid in the same provider:
import { Component } from '@angular/core';
import { RevoGrid } from '@revolist/angular-datagrid';
import { HistoryPlugin } from '@revolist/revogrid-pro';
import { GridControlsProvider } from '@revolist/revogrid-pro/angular';
import { CustomToolbar } from './custom-toolbar';
@Component({
standalone: true,
imports: [RevoGrid, GridControlsProvider, CustomToolbar],
template: `
<revo-grid-controls-provider>
<custom-toolbar />
<revo-grid style="height:240px" [source]="rows"
[plugins]="plugins" [columns]="columns" />
</revo-grid-controls-provider>
`,
})
export class TeamGrid {
plugins = [HistoryPlugin];
columns = [{ prop: 'name', name: 'Name' }];
rows = [{ name: 'Design' }, { name: 'Engineering' }];
}Import the Pro stylesheet in your global styles. The Angular provider's content query cannot find a grid hidden inside another component's private view. Keep the provider at the level where the grid is projected, or use an explicit connection where appropriate.
If you only need standard undo/redo buttons, use HistoryControls from your framework entry rather than the custom adapter. The provider also supports controls for batch editing, filtering, formatting, pagination, status lines, formulas, audit history and export. Each needs its matching plugin and configuration.
Custom controls make sense for application-specific layout, accessibility requirements, business actions and integration with your own design system. Keep options and translation objects stable; replacing them can reconnect controls and reset unfinished forms. The provider is scoped to one grid: use separate or nested providers for independent grids. React and Vue return null outside a provider; Angular injection needs an appropriate provider.
The scoped grid controls demo and framework control guide show the packaged integrations.
Start with two grids. Edit Design and verify only its Undo control becomes enabled. Undo via the button, Redo via the grid shortcut, then confirm the toolbar follows both. Replace one grid with another while a connection is pending. Remove a grid and check its controls disable; remount it and confirm they reflect the new instance's state.
Also test an absent HistoryPlugin, a rejected external history replay, rapid edits, and unmounting a toolbar while a plugin lookup is outstanding. In React, test development Strict Mode; in Vue, unmount the component; in Angular, destroy its view. None should leave listeners on the old grid.
AG Grid's React API documentation shows accessing the grid API through a component ref or grid-ready event. A ref is a perfectly reasonable pattern for one external action and can be wrapped in a custom context for larger applications.
RevoGrid's provider standardizes scoped discovery and replacement across three frameworks, including its packaged controls. It does not remove the need to subscribe to the specific plugin state or handle errors. The choice is between a reusable connection layer and maintaining those bindings separately in each application.
For a concrete data workflow that benefits from synchronized history controls, see the Event Manager guide and React data grid guide. The Pro trial includes the framework integrations.
See RevoGrid vs AG Grid for a wider grid-library comparison.
Keep exploring

Compare the original, draft and authoritative server values before retrying a rejected batch.

Keep undo history attached to records, not visual row indexes, when React or a server owns the data.