Hi~,
I need to specify two tasks to exchange positions
Here is an example. On the surface, it seems that I need it, but in essence, I find that I don’t realize the position exchange of two specified tasks
well
Hello,
If you want to swap the position of two tasks, and you know its IDs, then you can use moveTask
method to change the positions of the required tasks:
https://docs.dhtmlx.com/gantt/api__gantt_movetask.html ;
You need to get the index and the parent of the task by getTaskIndex
and getParent
methods:
https://docs.dhtmlx.com/gantt/api__gantt_gettaskindex.html;
https://docs.dhtmlx.com/gantt/api__gantt_getparent.html ;
So, to swap certain tasks might look like:
function swap() {
let temp_ind = gantt.getTaskIndex(1)
let temp_par = gantt.getParent(1)
gantt.moveTask(1, gantt.getTaskIndex(4), gantt.getParent(4));
gantt.moveTask(4, temp_ind, temp_par);
}
where temp_ind
, temp_par
temporary variables that hold the value of the initial task.
Please check the example:
https://snippet.dhtmlx.com/xuwfgkfm ;
Also, If you want to swap two selected tasks, one of the options is to use multiselect
extension to select certain tasks and using moveTask
method:
https://docs.dhtmlx.com/gantt/desktop__multiselection.html ;
You can use eachSelectedTask
method to get all selected tasks:
https://docs.dhtmlx.com/gantt/api__gantt_eachselectedtask.html ;
Please check the example of how it might be implemented (select two tasks by ctrl + click
and click at the button):
https://snippet.dhtmlx.com/u1xui7vc