onBeforeTaskMove

fires before a task is moved to a new vertical position

boolean onBeforeTaskMove(string|number id,string|number parent,number tindex);
idstring|numberthe id of the task to move
parentstring|numberthe parent id
tindexnumberthe index of the position in the parent branch that the task will be moved to
booleandefines whether the default action of the event will be triggered (true) or canceled (false)

Example

//prevent moving to another sub-branch:
gantt.attachEvent("onBeforeTaskMove", function(id, parent, tindex){
    const task = gantt.getTask(id);
    if(task.parent != parent)
        return false;
    return true;
});

Details

The event is blockable. Return false to cancel moving of the task.

Note, the event fires in 2 cases:

  1. While calling the method moveTask
  2. While the option order_branch is enabled in the default mode (gantt.config.order_branch = true;) and a user drags tasks
See also
Back to top