Bring VisActor visualization skills to your agent.
!!!###!!!title=context menu plugin——VisActor/VTable tutorial documents!!!###!!!
ContextMenu
Introduction
ContextMenu provides rich right-click menu features for VTable tables, supporting customization of right-click menus in different areas of the table (header, body, row series number, column series number, corner). It can effectively improve the interactive experience and operation efficiency of the table. Through this plugin, users can quickly perform common operations such as copying, pasting, inserting and deleting rows and columns, and freezing rows and columns.
Features
Support customization of right-click menus in different areas of the table (header, body, row series number, column series number, corner)
Built-in common menu operations (copy, paste, insert and delete rows and columns, freeze rows and columns, etc.)
Support custom menu items and separators
Support menu item grouping and submenus
Support custom menu item click callbacks
Support listening to menu item click events with menu item and cell position details
Support menu item icons and shortcut hints
Support numeric input in menu items (e.g., insert multiple rows/columns)
Basic Usage
Here is the basic usage method of the ContextMenu plugin:
The ContextMenu plugin supports dynamically adjusting menu items before they are displayed, which is very useful in some scenarios:
import * as VTable from'@visactor/vtable';
import { ContextMenuPlugin } from'@visactor/vtable-plugins';
// Create table instance (code omitted)...// Initialize the right-click menu pluginconst contextMenuPlugin = new ContextMenuPlugin({
// Use default menu items// Dynamically adjust menu items before they are displayedbeforeShowAdjustMenuItems: (menuItems, table, col, row) => {
// Dynamically adjust menu items based on cell position, content, etc.if (table.isHeader(col, row)) {
// Additional processing in the header areareturn [
...menuItems,
'---',
{ text: '自定义表头操作', menuKey: 'custom_header_action' }
];
}
// Get cell dataconst cellValue = table.getCellValue(col, row);
// Dynamically add menu items based on cell valuesif (typeof cellValue === 'number' && cellValue > 100) {
return [
...menuItems,
'---',
{ text: '高亮大数值', menuKey: 'highlight_large_value' }
];
}
return menuItems;
}
});
Listen to Menu Item Click Events
If you need to observe user actions after a right-click menu item is clicked, listen to the context_menu_click event fired by ContextMenuPlugin. This event is only fired after the right-click menu plugin is installed and enabled, and it is fired after the corresponding menu item handling logic is called. Note that when menuClickCallback is configured as a function, the plugin runs that callback and skips the built-in menu handling. Built-in operations such as freeze, insert, and delete are only executed when menuClickCallback is not configured, or when it is configured as an object and the current menuKey does not match a custom callback.