How to limit to move a event to another section in Timeline


#1

Hi ,

I have a use case, in timeline view, the event can not be moved from section to another. how to implement it.
I noticed the onLimitViolation. But it just can limit to set the date of the event into a blocked time, and the event will be back to the original place automatically.

I want a similar function. if the event is moved to another section, the event will be back to the original place automatically.


#2

Hi Lypch,
there is no special tool in the Scheduler to limit the event from dragging to other sections, but you can do it using Scheduler’s API.
In order to prevent events from changing the section when dragging the task, please use onBeforeDrag and onBeforeEventChanged events.
When onBeforeDrag fires, you can save the original section of the task using a flag variable:

var originalSection;
scheduler.attachEvent("onBeforeDrag", function (id, mode, e){
  var currentTask = scheduler.getEvent(id);
  if (mode != "create"){
    originalSection = currentTask.section_id;
  }
  return true;
});

So that section does not change when onBeforeEventChanged fires, please assign the task a previously saved section:

scheduler.attachEvent("onBeforeEventChanged", function(ev, e, is_new, original){
  if(!is_new){
  ev.section_id = original.section_id;
}
return true;
});

API onBeforeDrag:
https://docs.dhtmlx.com/scheduler/api__scheduler_onbeforedrag_event.html
API onBeforeEventChanged:
https://docs.dhtmlx.com/scheduler/api__scheduler_onbeforeeventchanged_event.html
In order to show that the task can’t be dragged to other sections, I change the opacity via event_class. I implemented the solution in the demo:
https://snippet.dhtmlx.com/5/3ce77c4eb


#3

Hi , thanks a lot. but I think we already had the relatively information in the onBeforeEventChanged.
I think the ev represent the new event after draged. and original represent the old event before draged.

right?


#4

Hi @lypch

Yes, it described in the onBeforeEventChanged documentation, please pay attention to Parameters.