Skip to content

Rows and Columns Context Menu

This example demonstrates how to create separate context menus with interactive actions for grid rows and columns. Use the same ContextMenuPlugin, but pass row actions through rowContextMenu and column-header actions through columnContextMenu.

Key Features:

  • Separate row and column context menu configurations
  • Actions with visual indicators
  • Styled menu buttons with hover effects

Source code
src/components/row-header/rowHeader.ts
import '@fortawesome/fontawesome-free/css/all.min.css';
import { defineCustomElements } from '@revolist/revogrid/loader';
defineCustomElements();
import { currentTheme, useRandomData } from '../composables/useRandomData';
import {
ContextMenuPlugin,
RowHeaderPlugin,
ColumnStretchPlugin,
RowOddPlugin,
} from '@revolist/revogrid-pro';
import {
columnContextMenuConfig,
rowContextMenuConfig,
} from './context-menu.config';
const { createRandomData } = useRandomData();
const { isDark } = currentTheme();
export function load(parentSelector: string) {
const parent = document.querySelector(parentSelector);
if (!parent) {
return;
}
const grid = document.createElement('revo-grid');
grid.source = createRandomData(100);
// Define columns
grid.columns = [
{
name: '#',
prop: 'id',
size: 70,
pin: 'colPinStart',
},
{
name: '🍎 Fruit',
prop: 'name',
},
{
name: '💰 Price',
prop: 'price',
pin: 'colPinEnd',
},
];
// Define plugin
grid.plugins = [
RowHeaderPlugin,
ContextMenuPlugin,
ColumnStretchPlugin,
RowOddPlugin,
];
// grid.rowHeaders = rowHeaders({ showHeaderFocusBtn: true });
Object.assign(grid, {
// Define separate context menus for row and column targets
rowContextMenu: rowContextMenuConfig,
columnContextMenu: columnContextMenuConfig,
stretch: 'all',
});
// Set theme
grid.theme = isDark() ? 'darkMaterial' : 'material';
grid.hideAttribution = true;
parent.appendChild(grid);
}