Update the % of Task father

Hello :slight_smile:

It is possible to during the updates of child’s tasks percentage, the task father being automatically updated as well?

Or, when the page load, and show the gantt chart, show the percentage updated.

Thanks

Hi,
you can recalculate parent percentage after the task is modified:
docs.dhtmlx.com/gantt/api__gantt … event.html
docs.dhtmlx.com/gantt/api__gantt_getparent.html
docs.dhtmlx.com/gantt/api__gantt_updatetask.html

But there is a way to calculate the percentage of father based on the percentage of each child?

For each parent you can recursively get percentage of it’s child tasks. How do you calculate the resulting value - simply take the average, or apply a more complex logic using durations of tasks or a custom properties - it should be handled by your application.

docs.dhtmlx.com/gantt/api__gantt … ldren.html

I did this, hope it helps :slight_smile:

gantt.attachEvent(“onAfterTaskDrag”, function(id, progress, e){

var task = gantt.getTask(id);
var parent = task.parent;                           

if(parent != 0)
{
    var final_value = 0;

    var sum_child_duration = 0;

    var parent_task = gantt.getTask(parent); 
    var parent_duration = parseInt(parent_task.duration);

    var all_childs = gantt.getChildren(parent);
    
    gantt.eachTask(function something(all_childs){
        var child_duration = all_childs.duration;
        var child_progress = all_childs.progress;

        final_value += child_duration*child_progress;

        sum_child_duration += parseInt(child_duration);

    }, parent);

    var dif;

    if(sum_child_duration < parent_duration)
    {
        dif = Math.abs(sum_child_duration-parent_duration);
        var final_progress = final_value/(parent_duration-dif);
    }else if(sum_child_duration > parent_duration){
        dif = Math.abs(sum_child_duration-parent_duration);
        var final_progress = final_value/(parent_duration+dif);
    }else{
        dif = 0;                                     
        var final_progress = final_value/(parent_duration-dif);
    }                              

    

    parent_task.progress = final_progress;

    gantt.updateTask(parent); 
}else{

}                

});

1 Like