Refresh timeline after calling gantt.date.add

Hey everyone,

I’ve added a button in my gantt to allow users to advance all the children tasks of a given parent a certain number of days.

Everything works, all the tasks get new start_dates, but only when I click each one they refresh on the timeline to the correct day.

This is what I’m doing:

gantt.eachTask(function abcd(curTask) {
                                curTask.start_date = gantt.date.add(curTask.start_date, parseInt(days), 'day');
                                gantt.updateTask(id);
                            }, id);

Isn’t updateTask the correct way to refresh a task in the timeline?

Thanks in advance.

Hello Xotik,
Looks like, you update the parent task instead of the child task. To update the correct task, you need to specify the child ID:

gantt.updateTask(curTask.id);

However, if you want to push tasks, it is not enough to update their start_date parameter. You can use calculateEndDate method to update the end_date parameter:
https://docs.dhtmlx.com/gantt/api__gantt_calculateenddate.html
Here is an example:
http://snippet.dhtmlx.com/dde3f5102

Hi Ramil,

Thank you for your reply, especially the calculateenddate, was missing that and having tasks falling on weekends!

I ended up calling gantt.refreshData() after updating all tasks, instead of gantt.updateTask(curTask.id) and it’s working fine now. Is there a problem with this alternative can you can think of?

Only one thing missing: is there a way to programmatically advance the timeline to show a specific task? Because when I click the button the timeline goes back to the parent, so I wanted to automatically advance the timeline to the updated tasks, show the first children for example.

Thank you so much for your help.

Hello Xotik,

I ended up calling gantt.refreshData() after updating all tasks, instead of gantt.updateTask(curTask.id) and it’s working fine now. Is there a problem with this alternative can you can think of?

It will improve the performance. But if you use the Data Processor to send the changes to the backend, the changes won’t be saved after pushing child tasks.

Only one thing missing: is there a way to programmatically advance the timeline to show a specific task? Because when I click the button the timeline goes back to the parent, so I wanted to automatically advance the timeline to the updated tasks, show the first children for example.

To advance the timeline, you need to have 2 things:

  1. Use gantt.render() instead of gantt.refreshData().
    If you didn’t specify the date range, it is enough to use gantt.render() function.
    If you specified the date range, you need to update it. For example:
if (+curTask.end_date < +date_range.max_date)  date_range.max_date = curTask.end_date;
  1. Use gantt.showTask(id) function to scroll to the task.

Here is the updated snippet:
http://snippet.dhtmlx.com/04b657a35

It’s working flawlessly Ramil, many thanks for your help :slight_smile: