Page 1 of 1

[REACT] Wrong project start date

Posted: Fri Jan 22, 2021 9:53 am
by sandippatel

Hello

I am facing weird issue in my project. I have tasks and each has start date. But when render it on Gantt chart it shows wrong start date.

Please find the attached screenshot. I am using React Advance demo with following .json.

invalid start.PNG
invalid start.PNG (104.37 KiB) Viewed 544 times
loadjson.json
(7.91 KiB) Downloaded 77 times

Re: [REACT] Wrong project start date

Posted: Fri Jan 22, 2021 12:21 pm
by pmiklashevich

Hello,

It works as expected. Project start date is required to be passed to perform calculations. We take it as the earliest SPECIFIED date in the data. Not calculated date. And then we never update the project start date automatically. So you can try to update the project start date when the calculation is done and data is ready. There are 'refresh' and 'dataready' events on the project. There is a ticket to make them public: https://github.com/bryntum/support/issues/2019

So you can try to do the following (just a concept to show the idea):

const calcStartDate = taskStore => {
    let startDate = taskStore.getTotalTimeSpan().endDate;

if (startDate) {
    taskStore.forEach(task => {
        if (task.startDate.getTime() <= startDate.getTime()) {
            startDate = task.startDate;
        }
    });
}

return startDate;
};

gantt.project.on({
    dataReady : () => {
        const startDate = calcStartDate(gantt.taskStore);

    if (startDate && (startDate.getTime() !== gantt.project.startDate?.getTime())) {
        console.log('Project start date is updated');
        gantt.project.startDate = new Date(startDate.getTime());
    }
}
});

I've opened a feature request to provide a config to track project changes and update its start date automatically. https://github.com/bryntum/support/issues/2274

Best,
Pavel