Skip to content

Events And Methods

Move a task toward the configured freeze window to exercise a cancelable before-change event. The custom row actions dispatch application events without installing methods on the grid.

Source code
import { defineCustomElements } from '@revolist/revogrid/loader';
defineCustomElements();
import { GanttPlugin } from '@revolist/gantt';
import { currentTheme } from '../composables/useRandomData';
import './gantt-example-recipes.css';
import {
RECIPE_ASSIGNMENTS,
RECIPE_CALENDARS,
RECIPE_COLUMNS,
RECIPE_DEPENDENCIES,
RECIPE_GANTT_CONFIG,
RECIPE_PANEL_ROWS,
RECIPE_PANEL_SOURCE_REFERENCES,
RECIPE_RESOURCES,
RECIPE_ROW_CONTEXT_MENU,
RECIPE_TASKS,
attachRecipeValidation,
} from './GanttExampleRecipesShared';
const { isDark } = currentTheme();
function createPanel(): HTMLElement {
const panel = document.createElement('aside');
panel.className = 'gantt-recipe-panel';
panel.innerHTML = `
<div class="gantt-recipe-panel__header">
<strong>Feature recipes</strong>
<span>Live outputs from exported example helpers</span>
</div>
<dl class="gantt-recipe-panel__list">
${RECIPE_PANEL_ROWS.map(
(row) => `
<div>
<dt>${row.label}</dt>
<dd>${row.value}</dd>
</div>
`,
).join('')}
</dl>
<div class="gantt-recipe-panel__sources">
${RECIPE_PANEL_SOURCE_REFERENCES.map((source) => `<code>${source}</code>`).join('')}
</div>
`;
return panel;
}
export function load(parentSelector: string) {
const parent = document.querySelector(parentSelector);
if (!parent) {
return () => {};
}
const root = document.createElement('section');
root.className = 'gantt-recipe-demo';
const grid = document.createElement('revo-grid');
grid.className = 'gantt-recipe-grid';
grid.theme = isDark() ? 'darkCompact' : 'compact';
grid.hideAttribution = true;
grid.plugins = [GanttPlugin];
grid.columns = RECIPE_COLUMNS;
grid.gantt = RECIPE_GANTT_CONFIG;
grid.ganttDependencies = RECIPE_DEPENDENCIES;
grid.ganttCalendars = RECIPE_CALENDARS;
grid.ganttResources = RECIPE_RESOURCES;
grid.ganttAssignments = RECIPE_ASSIGNMENTS;
grid.rowContextMenu = RECIPE_ROW_CONTEXT_MENU;
root.appendChild(grid);
root.appendChild(createPanel());
parent.appendChild(root);
const detachValidation = attachRecipeValidation(grid);
grid.source = RECIPE_TASKS;
return () => {
detachValidation();
root.remove();
};
}

Outside plugin code, locate the runtime through the grid’s plugin collection.

import { GanttPlugin } from '@revolist/gantt';
const plugins = await grid.getPlugins();
const gantt = plugins.find((plugin) => plugin instanceof GanttPlugin);

Do not install reverse callbacks or custom methods directly on the grid element.

PurposeMethods
Project lifecycleapplyGantt, clearGantt, getProjectSnapshot, getScheduledTasks
Zoom and rangezoomIn, zoomOut, setZoomLevel, getZoomLevel, canZoomIn, canZoomOut, getVisibleRange
TaskscreateTask, updateTask, finalizeTaskCreate, discardTaskCreate
HierarchyindentTask(s), outdentTask(s), deleteTask(s), convertTask(s)ToMilestones
BaselinescaptureBaseline

getProjectSnapshot() returns the authored project collections. Use getScheduledTasks() for the effective task dates after dependencies, calendars, and summary rollups. The built-in task editor and Fit action use those effective dates. Closing the editor or saving unchanged values preserves the authored inputs. Treat returned task collections as read-only; apply changes through updateTask().

Use the Gantt API for exact signatures and return types.

Call preventDefault() to reject a proposed packaged mutation.

grid.addEventListener('gantt-before-task-change', (event) => {
if (!canEditTask(event.detail.taskId, event.detail.action)) {
event.preventDefault();
}
});
EventWhen it fires
gantt-before-task-changeBefore create, move, resize, edit, progress, split, indent, outdent, delete, or milestone conversion.
gantt-before-dependency-changeBefore dependency create, delete, edit, or set replacement.
gantt-before-assignment-changeBefore task assignments are edited.

Gantt publishes successful task, dependency, and assignment mutations through EventManager’s existing gridedit event. This gives persistence and audit integrations one committed-change stream for grid edits and Gantt interactions such as moving, resizing, changing progress, editing hierarchy, and deleting tasks.

grid.addEventListener('gridedit', (event) => {
for (const change of event.detail.domainChanges ?? []) {
if (change.type === 'gantt-task') {
if (change.detail.task) saveTask(change.detail.task);
}
}
});

Use event.detail.eventTypes to detect gantt-task-change, gantt-dependency-change, or gantt-assignment-change. domainChanges preserves the committed changes in order and includes previous and current domain state. Bulk operations and scheduler cascades include every affected task.

data, previousData, and models keep the normal grid row/field shape. Stable task-row updates appear there exactly like other grid edits; dependencies, assignments, creates, deletes, and reorders that do not have a safe row coordinate stay in domainChanges. Replay-only project snapshots are stored separately in history and are never mixed into grid fields.

Cancellation belongs to the corresponding gantt-before-*-change event. A Gantt change in gridedit has already committed, so calling preventDefault() there does not roll it back. When EventManager collection is enabled, consecutive Gantt mutations are emitted as one collected transaction and one history step.

The grid also uses typed events for task creation/edit requests, hierarchy commands, zoom, search, dependency hover/selection, task-created notification, and panel resize. Prefer exported event constants when code must be refactor-safe.

import { GANTT_TASK_CREATE_EVENT, GANTT_ZOOM_IN_EVENT } from '@revolist/gantt';
grid.dispatchEvent(new CustomEvent(GANTT_TASK_CREATE_EVENT));
grid.dispatchEvent(new CustomEvent(GANTT_ZOOM_IN_EVENT));

Application listeners should update or validate project data, not query rendered task-bar geometry. See Application State for persistence ownership.