import { defineCustomElements } from '@revolist/revogrid/loader';
defineCustomElements();
import {
AutoFillPlugin,
CellFlashPlugin,
ColumnStretchPlugin,
EventManagerPlugin,
HistoryPlugin,
RowEditPlugin,
RowOddPlugin,
RowSelectPlugin,
} from '@revolist/revogrid-pro';
import { currentTheme } from '../composables/useRandomData';
import { defineHistoryControls } from '@revolist/revogrid-pro';
import {
createHistoryColumns,
createHistoryRows,
historyColumnTypes,
historyEditors,
} from './history-demo-data';
const { isDark } = currentTheme();
export function load(parentSelector: string) {
const parent = document.querySelector(parentSelector);
if (!parent) return;
const container = document.createElement('div');
container.className = 'grow flex flex-col h-full';
const grid = document.createElement('revo-grid') as HTMLRevoGridElement;
grid.className = 'cell-border grow';
grid.range = true;
grid.hideAttribution = true;
grid.columnTypes = historyColumnTypes;
grid.editors = historyEditors;
grid.eventManager = {
applyEventsToSource: true,
};
grid.theme = isDark() ? 'darkMaterial' : 'material';
grid.stretch = 'all';
grid.history = {
undoStack: [],
redoStack: [],
maxStackSize: 200,
disabled: false,
};
grid.columns = createHistoryColumns();
grid.plugins = [
EventManagerPlugin,
HistoryPlugin,
AutoFillPlugin,
RowEditPlugin,
ColumnStretchPlugin,
CellFlashPlugin,
RowOddPlugin,
RowSelectPlugin,
];
// Toolbar with undo/redo — created after grid is in DOM so getPlugins() works
container.appendChild(grid);
parent.appendChild(container);
const toolbar = document.createElement('div');
container.prepend(toolbar);
defineHistoryControls(toolbar, grid);
grid.source = createHistoryRows();
return () => container.remove();
}
// src/components/history/History.tsx
import { useState, useMemo, useRef, useEffect } from 'react';
import { RevoGrid, type DataType } from '@revolist/react-datagrid';
import {
AutoFillPlugin,
CellFlashPlugin,
ColumnStretchPlugin,
EventManagerPlugin,
HistoryPlugin,
RowEditPlugin,
RowOddPlugin,
RowSelectPlugin,
defineHistoryControls,
type HistoryConfig,
} from '@revolist/revogrid-pro';
import { currentTheme } from '../composables/useRandomData';
import {
createHistoryColumns,
createHistoryRows,
historyColumnTypes,
historyEditors,
} from './history-demo-data';
function History() {
const { isDark } = currentTheme();
const gridRef = useRef<HTMLRevoGridElement>(null);
const toolbarRef = useRef<HTMLDivElement>(null);
const [source] = useState<DataType[]>(() => createHistoryRows());
const history = useMemo<HistoryConfig>(() => ({
undoStack: [],
redoStack: [],
maxStackSize: 200,
disabled: false,
}), []);
const columns = useMemo(() => createHistoryColumns(), []);
const columnTypes = useMemo(() => historyColumnTypes, []);
const editors = useMemo(() => historyEditors, []);
const eventManager = useMemo(() => ({ applyEventsToSource: true }), []);
const plugins = useMemo(() => [
EventManagerPlugin,
HistoryPlugin,
AutoFillPlugin,
RowEditPlugin,
ColumnStretchPlugin,
CellFlashPlugin,
RowOddPlugin,
RowSelectPlugin,
], []);
useEffect(() => {
if (toolbarRef.current && gridRef.current) {
defineHistoryControls(toolbarRef.current, gridRef.current);
}
}, []);
return (
<div className="grow flex flex-col h-full">
<div ref={toolbarRef} />
<RevoGrid
ref={gridRef}
className="cell-border grow"
theme={isDark() ? 'darkMaterial' : 'material'}
columns={columns}
source={source}
plugins={plugins}
columnTypes={columnTypes}
editors={editors}
eventManager={eventManager}
history={history}
range
stretch="all"
hideAttribution
/>
</div>
);
}
export default History;
// src/components/history/History.vue
<template>
<div class="grow flex flex-col h-full">
<div ref="toolbarRef"></div>
<VGrid
class="cell-border grow"
ref="gridRef"
:theme="isDark ? 'darkMaterial' : 'material'"
:columns="columns"
:source="rows"
:plugins="plugins"
:columnTypes="columnTypes"
:editors="editors"
:eventManager="eventManager"
:history="history"
:range="true"
stretch="all"
hide-attribution
/>
</div>
</template>
<script setup lang="ts">
import { nextTick, onMounted, ref } from 'vue';
import { currentThemeVue } from '../composables/useRandomData';
import { VGrid } from '@revolist/vue3-datagrid';
import {
AutoFillPlugin,
CellFlashPlugin,
ColumnStretchPlugin,
EventManagerPlugin,
HistoryPlugin,
RowEditPlugin,
RowOddPlugin,
RowSelectPlugin,
defineHistoryControls,
type HistoryConfig,
} from '@revolist/revogrid-pro';
import {
createHistoryColumns,
createHistoryRows,
historyColumnTypes,
historyEditors,
} from './history-demo-data';
const { isDark } = currentThemeVue();
const gridRef = ref<HTMLRevoGridElement | null>(null);
const toolbarRef = ref<HTMLElement | null>(null);
const columns = ref(createHistoryColumns());
const columnTypes = historyColumnTypes;
const editors = historyEditors;
const eventManager = { applyEventsToSource: true };
const plugins = ref([
EventManagerPlugin,
HistoryPlugin,
AutoFillPlugin,
RowEditPlugin,
ColumnStretchPlugin,
CellFlashPlugin,
RowOddPlugin,
RowSelectPlugin,
]);
const rows = ref(createHistoryRows());
const history: HistoryConfig = {
undoStack: [],
redoStack: [],
maxStackSize: 200,
disabled: false,
};
onMounted(async () => {
await nextTick();
const toolbar = toolbarRef.value;
if (!toolbar) {
return;
}
const grid = ((gridRef.value as any)?.$el ?? gridRef.value) as HTMLRevoGridElement | null;
if (!grid || typeof grid.addEventListener !== 'function' || typeof grid.getPlugins !== 'function') {
return;
}
defineHistoryControls(toolbar, grid);
});
</script>
import { Component, ViewChild, ElementRef, ViewEncapsulation, AfterViewInit, NO_ERRORS_SCHEMA } from '@angular/core';
import { RevoGrid } from '@revolist/angular-datagrid';
import {
AutoFillPlugin,
CellFlashPlugin,
ColumnStretchPlugin,
EventManagerPlugin,
HistoryPlugin,
RowEditPlugin,
RowOddPlugin,
RowSelectPlugin,
defineHistoryControls,
type HistoryConfig,
} from '@revolist/revogrid-pro';
import { currentTheme } from '../composables/useRandomData';
import {
createHistoryColumns,
createHistoryRows,
historyColumnTypes,
historyEditors,
} from './history-demo-data';
@Component({
selector: 'history-grid',
standalone: true,
imports: [RevoGrid],
template: `
<div class="grow flex flex-col h-full">
<div #toolbar></div>
<revo-grid
#grid
class="cell-border grow"
[theme]="theme"
[columns]="columns"
[source]="rows"
[plugins]="plugins"
[columnTypes]="columnTypes"
[editors]="editors"
[eventManager]="eventManager"
[history]="history"
[range]="true"
stretch="all"
[hideAttribution]="true"
></revo-grid>
</div>
`,
encapsulation: ViewEncapsulation.None,
// Allows Angular demos to bind RevoGrid plugin props that are not wrapper inputs.
schemas: [NO_ERRORS_SCHEMA],
})
export class HistoryGridComponent implements AfterViewInit {
@ViewChild('grid', { read: ElementRef }) gridElement!: ElementRef;
@ViewChild('toolbar', { read: ElementRef }) toolbarElement!: ElementRef;
theme = currentTheme().isDark() ? 'darkMaterial' : 'material';
rows = createHistoryRows();
history: HistoryConfig = {
undoStack: [],
redoStack: [],
maxStackSize: 200,
disabled: false,
};
columnTypes = historyColumnTypes;
editors = historyEditors;
eventManager = { applyEventsToSource: true };
columns = createHistoryColumns();
plugins = [
EventManagerPlugin,
HistoryPlugin,
AutoFillPlugin,
RowEditPlugin,
ColumnStretchPlugin,
CellFlashPlugin,
RowOddPlugin,
RowSelectPlugin,
];
ngAfterViewInit() {
defineHistoryControls(this.toolbarElement.nativeElement, this.gridElement.nativeElement);
}
}