The TOP 3 JavaScript Gantt chart. Discover their features, advantages, and disadvantages to choose the best tool for your project.
ScheduleJS allows you to build complex drag-and-drop interactions, including side effects. This article will discuss how to build advanced drag-and-drop operations using the framework customization APIs.
ScheduleJS supports drag-and-drop by default. The base behavior is the following:
To edit this behavior, a set of methods is made available to the developer.
The method to edit the drag-and-drop operation mode is:
graphics.setEditModeCallback(Activity, Layout, callback)
It will let you set which drag-and-drop operation you want to use for a specific Activity and LayoutType. You can build logic based on the activity data and from the event that its callback receives.
Let’s see how we can implement this with the following example:
// Register a new edit mode callback for MyActivity in a GanttLayout
graphics.setEditModeCallback(MyActivity, GanttLayout, myEditModeCallback);
// This callback will disallow drag-and-drop if no modifier key is pressed
const myEditModeCallback = (event: EditModeCallbackParameter) => {
if (event.getPointerEvent().shiftKey) {
return EditModeEnum.DRAGGING;
}
if (event.getPointerEvent().ctrlKey) {
return EditModeEnum.DRAGGING_HORIZONTAL;
}
return EditModeEnum.NONE;
};
In this example, the myEditModeCallback
function will receive an event
parameter of type EditModeCallbackParameter holding the ActivityBounds (which in turn holds an ActivityRef) and the native JavaScript PointerEvent. It will trigger whenever the user hovers any activity of type MyActivity in a GanttLayout context.
The return value of this callback has to be of type EditModeEnum. The EditModeEnum holds the following drag-and-drop possibilities:
// The EditModeEnum
export declare enum EditModeEnum {
AGENDA_ASSIGNING = "AGENDA_ASSIGNING",
AGENDA_DRAGGING = "AGENDA_DRAGGING",
AGENDA_END_TIME_CHANGE = "AGENDA_END_TIME_CHANGE",
AGENDA_START_TIME_CHANGE = "AGENDA_START_TIME_CHANGE",
CHART_VALUE_CHANGE = "CHART_VALUE_CHANGE",
CHART_VALUE_HIGH_CHANGE = "CHART_VALUE_HIGH_CHANGE",
CHART_VALUE_LOW_CHANGE = "CHART_VALUE_LOW_CHANGE",
DELETING = "DELETING",
DRAGGING = "DRAGGING",
DRAGGING_HORIZONTAL = "DRAGGING_HORIZONTAL",
DRAGGING_VERTICAL = "DRAGGING_VERTICAL",
END_TIME_CHANGE = "END_TIME_CHANGE",
NONE = "NONE",
PERCENTAGE_COMPLETE_CHANGE = "PERCENTAGE_COMPLETE_CHANGE",
START_TIME_CHANGE = "START_TIME_CHANGE"
}
For example, to disallow a drag-and-drop operation, you can build a callback that evaluates the desired context and returns the EditModeEnum.NONE
value.
The following example shows a setup where the return value of this callback is EditModeEnum.DRAGGING_VERTICAL
Now that the drag-and-drop mode is set according to your needs, you might want to edit what happens when the user is dragging the Activity. To do so, ScheduleJS provides a set of methods to monitor and affect your application’s state at runtime:
graphics.onActivityDragStart((event: ActivityEvent) => callback)
will trigger a callback whenever a drag-and-drop operation startsgraphics.onActivityDragOngoing((event: ActivityEvent) => callback)
will trigger a callback whenever a drag-and-drop-operation is ongoinggraphics.onActivityDragFinished((event: ActivityEvent) => callback)
will trigger a callback whenever a drag-and-drop operation is finishedThe ActivityEvent holds an ActivityRef to get activity-related information, EventType information, the old TimeInterval before the operation, and extra specific information like the old and new Row in case you are in a vertical drag-and-drop context and the old value in case of a ChartLayout.
In addition to these three, the same sort of methods exist for:
The following example shows a use-case where we had to enforce activities order when using the drag-and-drop feature:
The TOP 3 JavaScript Gantt chart. Discover their features, advantages, and disadvantages to choose the best tool for your project.
Discover how ScheduleJS seamlessly integrated with Selligent CRM, enhancing scheduling efficiency for a leading beauty brand's consultants.
This article showcases the integration of a ScheduleJS component into an external Ag-Grid table, to demonstrate the flexibility of ScheduleJS.
How to synchronize multiple graphics? Learn how to reuse your ScheduleJS timeline in multiple graphics to keep them synchronized.
How to build an interactive context menu? A deep dive into ScheduleJS event handling and recommended practice to build your own context menu.
This article shows how to implement dynamic rendering depending on the current zoom-level of the graphics.
This article proposes a step-by-step implementation of an animation mechanism using JavaScript Date API for your activities.
This article will cover a websocket implementation featuring real time data rendering using the ScheduleJS drawing engine.
This article will go through the implementation of a custom info column using an AG Grid component in place of the default one.
This article will show you how the parent-child tree Gantt architecture within the ScheduleJS Viewer was built.