When I use gantt.updateTask, it does not update links

https://snippet.dhtmlx.com/xi9e26dt

Hello Team,

When I use gantt.updateTask to update the start_date, the dependent tasks are not updated. In my snippet link, you can see that I’m calling gantt.updateTask for Task #1.

This is unlike when I use drag-and-drop. If I drag Task 1 to to another day in the future, the other tasks are automatically updated according to the link type.

Can you please let me know how to fix this issue? I want to be able to call gantt.updateTask and have the other tasks and links update accordingly.

Thanks!

Hello,
If you update the task dates via the Gantt API, you need to manually call the autoSchedule method, and this is expected behavior:
https://docs.dhtmlx.com/gantt/api__gantt_autoschedule.html

1 Like

Thank you Ramil. I knew it was definitely me that was missing something - this library is so robust :slight_smile:

If I change the duration and the start_date, how do I handle the end date?

Would I need to use gantt.calculateEndDate like this - DHTMLX Snippet Tool

Just want to double check. Thanks!

Hello,
Thank you for the positive feedback!

The end_date property has a higher priority over the duration parameter. So, if you only update the duration parameter, it won’t change anything. If you update it with the start_date parameter, you will resize the task. So, yes, you need to manually update the end_date parameter by using the calculateEndDate method. If a task has a custom calendar, you also need to specify the task object as the third parameter:

task1.end_date = gantt.calculateEndDate({start_date: task1.start_date, duration: task1.duration, task: task1});

https://docs.dhtmlx.com/gantt/api__gantt_calculateenddate.html#:~:text=task%20-%20(object)%20optional%2C%20the%20object%20of%20the%20task%20the%20duration%20of%20which%20should%20be%20calculated

Also, it is not necessary to update a task by using the state approach (when you specify the task object as a second argument). You can update the task properties, then only specify the task’s ID in the updateTask method:

const task1 = gantt.getTask("1");
task1.start_date = new Date(2025, 3, 5);
task1.duration = 2;
task1.end_date = gantt.calculateEndDate({start_date: task1.start_date, duration: task1.duration});
gantt.updateTask(task1.id)
gantt.autoSchedule()

// or
const task1 = gantt.getTask("1");
const updatedParams = {
    start_date: new Date(2025, 3, 5),
    duration: 2,
    end_date: gantt.calculateEndDate({start_date: task1.start_date, duration: task1.duration})
}
gantt.mixin(task1, updatedParams, true)
gantt.updateTask(task1.id)
gantt.autoSchedule()