Skip to content

Event Manager

Learn how to handle, customize, and optimize events to create complex interactions and workflows with the Event Manager Plugin for RevoGrid. The main purpose of this plugin is to collect and dispatch edit events in one centralized location, simplifying event management.

The Event Manager Plugin aggregates various editing events into a single event, gridedit. This approach reduces the complexity of handling multiple event types individually, such as clipboardrangepaste, beforeedit, and beforerangeedit. By using the Event Manager Plugin, you can catch all these events through one unified event, making it a robust starting point for building your custom event management system.

Source code
import { defineCustomElements } from '@revolist/revogrid/loader';
defineCustomElements();
import { EventManagerPlugin } from '@revolist/revogrid-pro';
import { currentTheme, useRandomData } from '../composables/useRandomData';
const { createRandomData } = useRandomData();
const { isDark } = currentTheme();
export function load(parentSelector: string) {
const grid = document.createElement('revo-grid');
grid.range = true;
grid.source = createRandomData(100);
// Define columns
grid.columns = [
{
name: 'πŸ†” ID',
prop: 'id',
},
{
name: '🍎 Fruit',
prop: 'name',
},
{
name: 'πŸ’° Price',
prop: 'price',
},
];
// Define plugin
grid.plugins = [EventManagerPlugin];
grid.addEventListener('gridedit', (event) => {
const log = document.querySelector('.output .code');
if (!log) {
return;
}
log.innerHTML = JSON.stringify(event.detail);
});
grid.theme = isDark() ? 'darkCompact' : 'compact';
grid.hideAttribution = true;
document.querySelector(parentSelector)?.appendChild(grid);
}

Key Features

  • Centralized Event Handling: Collects multiple edit events into a single gridedit event.
  • Simplified Event Management: Reduces the need to manage numerous event types individually.
  • Customizable Workflows: Provides a foundation to create complex interactions and workflows.

Implementation

Here’s a brief overview of how to implement the Event Manager Plugin in your RevoGrid setup.

Step-by-Step Guide

  1. Import Required Modules: Import the necessary modules from the RevoGrid library to start setting up the Event Manager Plugin.

  2. Define Edit Details Type: Create a type for edit details that will help structure the event data.

  3. Create EventManagerPlugin Class: Develop the EventManagerPlugin class to handle and dispatch edit events. This class listens for various edit events and dispatches a unified gridedit event.

    • Collect Edit Events: Listens for clipboardrangepaste, beforeedit, and beforerangeedit events.
    • Dispatch Unified Event: Dispatches the gridedit event after collecting details from the various edit events.
  4. Add Plugin to RevoGrid: Attach the Event Manager Plugin to your RevoGrid instance and start listening for the gridedit event.

    ...
    grid.plugins = [EventManagerPlugin];
    ...

For detailed implementation, please refer to the full code below.

The Event Manager Plugin is a powerful tool for managing edit events. By consolidating multiple event types into a single, manageable event, it simplifies event handling and provides a solid foundation for developing custom workflows and interactions.