Copy full branch Task, child and links

Hi,

is there a function to copy a full branch of Task, including subtask and Links?

Thanks

Hello @MichaelHilgers,

There is no built-in function to do that, but it can be implemented through a custom solution, based on the gantt.copy(task) method, which creates a deep copy of a single task.

So you may clone the full branch by a loop through the task and his children, there is a method “hasChild(id)”.
So, all that you need, is to check if the “cloned” task has children iterates through these children with (for) loop.

Here is a demo:
http://snippet.dhtmlx.com/5/994a7dd9f

In this demo, clones are adding to the same chart as the original. The “id” attribute should be unique for each “task” and “link” In order to do this, I used the internal gantt’s method to assign unique “id” to clones: “gantt.uid()”.

If you want to extract clones to a different place, you don’t need to change “their/their links” id’s.

Here is a demo(Arrays with data will appear in browser’s console after clicking “V” button):
http://snippet.dhtmlx.com/5/0c489dba6

Here is another pretty base solution through the “eachTask()” function(Arrays with data will appear in browser’s console after clicking “V” button):
http://snippet.dhtmlx.com/5/ba8f7cc98

API:
copy:
https://docs.dhtmlx.com/gantt/api__gantt_copy.html
uid:
https://docs.dhtmlx.com/gantt/api__gantt_uid.html
hasChild:
https://docs.dhtmlx.com/gantt/api__gantt_haschild.html
eachTask:
https://docs.dhtmlx.com/gantt/api__gantt_eachtask.html