# Update the % of Task father

Hello

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

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

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

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

var sum_child_duration = 0;

var all_childs = gantt.getChildren(parent);

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);
}