Update Task Order with REST

I just started working on a project with gantt 5.0.5 in which I need to change the order of my tasks with the drag-and-drop feature. So I’ve been following along the Node.js example with gantt.config.order_branch = true (but I haven’t set gantt.config.order_branch_free because I want the tasks to stay on the same level):
docs.dhtmlx.com/gantt/desktop__ … deroftasks

The problem I’m running into is that in my app.put("/data/task/:id", …) function, the target I’m getting out is correct if I drag the task down but incorrect if I drag the task up the task list.

  • For example, when I drag “Task #1.1” on top of “Task #1.2”, I get a target of 6 for “Task #1.2”, which is correct.
  • But then when I drag it back up again on top of “Task #1.2”, I get a target of 3 for “Task #2”, which is wrong.
  • Similarly, when I drag “Task #2.2” on top of “Task #2.1”, I get a target of 4 for “Task #3”, which is wrong.

Please note that you don’t necessarily need a backend framework to replicate this issue. The following code should log it to the JavaScript console:
gantt.attachEvent(“onRowDragEnd”, function(id, target) {
console.log(id + ’ ’ + target);
});
on this example: docs.dhtmlx.com/gantt/samples/0 … ering.html .

I think this is a bug, but I may be missing something in how I’m parsing the event. Any assistance would be greatly appreciated–thank you!!!

(I just tested with the cdn.dhtmlx.com/ version 4.1.0 and it does not have this issue, but 5.0.5 does.)

Making the following changes to the source code brings the behavior close to (but not exactly the same as) v4.1.0:

On line 9972,
this._moveInner(this.getIndexById(sid), this.getIndexById(parent) + tindex + 1);

For tasksStore.attachEvent(“onAfterItemMove”, …) on line 9201, replace the function with:

tasksStore.attachEvent("onAfterItemMove", function(sid, parent, tindex){
	var source = gantt.getTask(sid);

	if (this.getNextSibling(sid)) {
		source.$drop_target = this.getNextSibling(sid);
	} else if (this.getPrevSibling(sid)) {
		source.$drop_target = "next:" + this.getPrevSibling(sid);
	} else {
		source.$drop_target = "next:" + this.getParent(sid);
	}

	return true;
});

The main difference between this logic and v4.1.0 is that when you are moving the item down without adding it to the end of that section, it will default to giving you the id of nextSibling rather than next: prevSibling as in v4.1.0 . In addition, I have not tested this for gantt.config.order_branch_free = true .

Please let me know if this helps or if DHTMLX comes out with a fix in the next version!

Hello,
we confirmed this regression in 5.0.5 version, it should be fixed in the latest dev builds and a public update will be released in mid-February 2018
If you PM me your license number or open a ticket in our support system, I can send you the latest build for a test