Skip to main content

Context Menu

Right-click any cell to open a context menu with clipboard operations, undo/redo, and selection actions. Keyboard shortcut labels are displayed alongside each item.

Live Demo

Right-click any cell to open the context menu
Live
Name
Department
Status
Salary
Alice Johnson
Engineering
Active
$50,000
Bob Smith
Marketing
Draft
$53,500
Carol Lee
Sales
Archived
$57,000
David Kim
Finance
Active
$60,500
Eve Torres
Operations
Draft
$64,000
Frank Wu
Engineering
Archived
$67,500
Grace Park
Marketing
Active
$71,000
Henry Adams
Sales
Draft
$74,500
Irene Costa
Finance
Archived
$78,000
Jack Rivera
Operations
Active
$81,500
Try it in your framework

The demo above uses Radix UI for styling. To see this feature with your framework's design system (Fluent UI, Material UI, Vuetify, PrimeNG, etc.), click "Open in online demo" below the demo.

Quick Example

import { OGrid } from '@alaarab/ogrid-react-radix';
import { useRef } from 'react';
import { useUndoRedo } from '@alaarab/ogrid-react-radix';

function App() {
const undoRedo = useUndoRedo();

return (
<OGrid
columns={columns}
data={data}
getRowId={(r) => r.id}
editable
onCellValueChanged={(e) => {
undoRedo.pushChange(e);
// persist change...
}}
onUndo={undoRedo.undo}
onRedo={undoRedo.redo}
canUndo={undoRedo.canUndo}
canRedo={undoRedo.canRedo}
/>
);
}
Switching UI libraries

The OGrid component has the same props across all React UI packages. To switch, just change the import:

  • Radix (lightweight, default): from '@alaarab/ogrid-react-radix'
  • Fluent UI (Microsoft 365 / SPFx): from '@alaarab/ogrid-react-fluent' — wrap in <FluentProvider>
  • Material UI (MUI v7): from '@alaarab/ogrid-react-material' — wrap in <ThemeProvider>

Right-click a cell to see the context menu with all available actions.

How It Works

The context menu is built in and requires no additional configuration. It appears when the user right-clicks on a data cell. Right-clicking on headers, empty space, or outside the grid does not open the menu.

Built-in Menu Items

ItemShortcutDescription
UndoCtrl+ZUndo the last cell edit
RedoCtrl+YRedo the last undone edit
CopyCtrl+CCopy selected cells to clipboard
CutCtrl+XCut selected cells to clipboard
PasteCtrl+VPaste clipboard contents into selected cells
Select allCtrl+ASelect all cells in the grid (cell selection, not row selection)

On macOS, "Ctrl" is automatically displayed as the Command symbol.

Cell Selection vs Row Selection

The "Select all" menu item selects all cells for copy/paste/fill operations. This is different from row selection, where the header checkbox selects all rows for bulk operations. See Row Selection for details on row-level selection.

Undo/Redo State

The Undo and Redo items reflect their availability through the canUndo and canRedo props. When canUndo is false, the Undo item appears disabled (grayed out). Same for Redo.

<OGrid
// ...
onUndo={undoRedo.undo}
onRedo={undoRedo.redo}
canUndo={undoRedo.canUndo}
canRedo={undoRedo.canRedo}
/>

If onUndo and onRedo are not provided, the undo/redo items still appear but do nothing.

Cell-Only Activation

The context menu only opens on cell right-clicks. This is intentional:

  • Header right-click: default browser context menu (no grid menu).
  • Empty space right-click: default browser context menu.
  • Cell right-click: grid context menu with actions scoped to the current selection.

Copy/Cut Disabled State

The Copy and Cut items are disabled when no cells are selected. Once the user clicks a cell or selects a range, these items become active.

Props Reference

TypeFieldDescription
IOGridProps<T>onUndoCallback invoked when Undo is clicked
IOGridProps<T>onRedoCallback invoked when Redo is clicked
IOGridProps<T>canUndoboolean -- disables Undo item when false
IOGridProps<T>canRedoboolean -- disables Redo item when false
IOGridProps<T>cellSelectionboolean -- context menu requires cell selection (default true)