import { defineCustomElements } from '@revolist/revogrid/loader';
defineCustomElements();
import {
cellFlashArrowTemplate,
CellFlashPlugin,
ColumnStretchPlugin,
EventManagerPlugin,
HistoryPlugin,
RowOddPlugin,
RowSelectPlugin,
} from '@revolist/revogrid-pro';
import { currentTheme, useRandomData } from '../composables/useRandomData';
import { defineHistoryControls } from '@revolist/revogrid-pro';
const { createRandomData } = useRandomData();
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.theme = isDark() ? 'darkMaterial' : 'material';
grid.stretch = 'all';
grid.history = {
undoStack: [],
redoStack: [],
maxStackSize: 200,
disabled: false,
};
grid.source = createRandomData(100);
grid.columns = [
{ name: 'ID', prop: 'id', rowSelect: true, size: 80 },
{ name: 'Fruit', prop: 'name' },
{
name: 'Price',
prop: 'price',
flash: () => true,
cellTemplate: cellFlashArrowTemplate(),
},
];
grid.plugins = [
EventManagerPlugin,
HistoryPlugin,
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);
}
// src/components/history/History.tsx
import { useState, useMemo, useRef, useEffect } from 'react';
import { RevoGrid, type DataType } from '@revolist/react-datagrid';
import {
cellFlashArrowTemplate,
CellFlashPlugin,
ColumnStretchPlugin,
EventManagerPlugin,
HistoryPlugin,
RowOddPlugin,
RowSelectPlugin,
defineHistoryControls,
type HistoryConfig,
} from '@revolist/revogrid-pro';
import { useRandomData, currentTheme } from '../composables/useRandomData';
function History() {
const { isDark } = currentTheme();
const { createRandomData } = useRandomData();
const gridRef = useRef<HTMLRevoGridElement>(null);
const toolbarRef = useRef<HTMLDivElement>(null);
const [source] = useState<DataType[]>(() => createRandomData(100));
const history = useMemo<HistoryConfig>(() => ({
undoStack: [],
redoStack: [],
maxStackSize: 200,
disabled: false,
}), []);
const columns = useMemo(() => [
{ name: 'ID', prop: 'id', rowSelect: true, size: 80 },
{ name: 'Fruit', prop: 'name' },
{ name: 'Price', prop: 'price', flash: () => true, cellTemplate: cellFlashArrowTemplate() },
], []);
const plugins = useMemo(() => [
EventManagerPlugin,
HistoryPlugin,
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}
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"
:history="history"
:range="true"
stretch="all"
hide-attribution
/>
</div>
</template>
<script setup lang="ts">
import { nextTick, onMounted, ref } from 'vue';
import { currentThemeVue, useRandomData } from '../composables/useRandomData';
import { VGrid } from '@revolist/vue3-datagrid';
import {
cellFlashArrowTemplate,
CellFlashPlugin,
ColumnStretchPlugin,
EventManagerPlugin,
HistoryPlugin,
RowOddPlugin,
RowSelectPlugin,
defineHistoryControls,
type HistoryConfig,
} from '@revolist/revogrid-pro';
const { createRandomData } = useRandomData();
const { isDark } = currentThemeVue();
const gridRef = ref<HTMLRevoGridElement | null>(null);
const toolbarRef = ref<HTMLElement | null>(null);
const columns = ref([
{ name: 'ID', prop: 'id', rowSelect: true, size: 80 },
{ name: 'Fruit', prop: 'name' },
{
name: 'Price',
prop: 'price',
flash: () => true,
cellTemplate: cellFlashArrowTemplate(),
},
]);
const plugins = ref([
EventManagerPlugin,
HistoryPlugin,
ColumnStretchPlugin,
CellFlashPlugin,
RowOddPlugin,
RowSelectPlugin,
]);
const rows = ref(createRandomData(100));
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 {
cellFlashArrowTemplate,
CellFlashPlugin,
ColumnStretchPlugin,
EventManagerPlugin,
HistoryPlugin,
RowOddPlugin,
RowSelectPlugin,
defineHistoryControls,
type HistoryConfig,
} from '@revolist/revogrid-pro';
import { currentTheme, useRandomData } from '../composables/useRandomData';
@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"
[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 = useRandomData().createRandomData(100);
history: HistoryConfig = {
undoStack: [],
redoStack: [],
maxStackSize: 200,
disabled: false,
};
columns = [
{ name: 'ID', prop: 'id', rowSelect: true, size: 80 },
{ name: 'Fruit', prop: 'name' },
{ name: 'Price', prop: 'price', flash: () => true, cellTemplate: cellFlashArrowTemplate() },
];
plugins = [
EventManagerPlugin,
HistoryPlugin,
ColumnStretchPlugin,
CellFlashPlugin,
RowOddPlugin,
RowSelectPlugin,
];
ngAfterViewInit() {
defineHistoryControls(this.toolbarElement.nativeElement, this.gridElement.nativeElement);
}
}