Rendering of Tasks without start_date and end_date


#1

I have tasks where the start_date and end_date are empty. The duration was set to 5. After rendering, the duration was set to 0 automatically and the task is not displayed in the timeline.
Is there a way to display these tasks with the start date of the parent task and the correct duration of 5 days?


#2

Hi,
I can suggest the following solution:

You can change the start_date of tasks while they are being loaded using the onTaskLoading handler. You also need to recalculate end_date tasks using the gantt.calculateEndDate method. It might look like this:

gantt.attachEvent("onTaskLoading", (task) => {
    if (!task.start_date) {
        const parentStartDate = gantt.getTask(task.parent).start_date;
        task.start_date = parentStartDate;
        task.end_date = gantt.calculateEndDate({start_date: task.start_date, duration: task.duration, task: task});
    }
    
    return true;
});

Here is a simple example: https://snippet.dhtmlx.com/rdh9t6jb


#3

That works fine. Thanks!