I integrated the gantt chart with my backend.
Interaction with the chart is 2-ways. Changes in the backend need to be propaged to the frontend and visa versa.
In my backend I only use duration, I never set the end_date.
Initially I load the data using gantt.parse. The gantt chart will internally calculate the end_date based on the start_date and duration. I use worktimes, so it takes that into account.
When updating a task in the backend and syncing to the frontend, in bulk:
Object.assign() for each task to overwrite the task properties. Since I have no end_date in the backend, it just overwites the start_date and end_date is untouched.
gantt.refreshData();
Since the end_date was already calculated, and end_date has higher priority than duration. So the task duration will be calculated. Depending if the task was moved forward or backward I even get negative durations.
What I really want is the end_date to be recalculated. I tried explicitly setting the end_date to null, but then I get a bunch of exceptions in the front end because end_date should not be null.
How can I fix this?
Is my approach of updating tasks wrong?
Should I manually re-trigger end_date calculation?
Is it possible to use parse as a means to update, or is this a bad idea?
Note that in the future, I might want to support end_date as well in the backend.
If you parse the data, the owner_id from a task will be picked up, but when updating as mentioned in the previous post, this does not happen. Please advise on this one as well.
Hello Tom,
If you have an existing chart and want to update the data from the server, it is better to use the parse method. When you call that method, Gantt doesn’t remove existing tasks. If the dataset in the parse method has the tasks that already exist, they will be updated, if there are new tasks, they will be added.
If you enable the third argument, Gantt will overwrite the target object but the existing properties remain if they are not present in the source object.
If you modify the task object and don’t call the updateTask method, it is expected that the resource data is not updated as Gantt doesn’t watch the task objects and doesn’t know that something changed: updateTaskAssignments Gantt Docs.
But, if you enable auto-scheduling and the auto_scheduling_initial config is turned on (default), loading tasks with the parse method may trigger the update events. The events are not called by the parse method. But after you load the data, Gantt calls the autoSchedule method, and because of that, the tasks may be updated.
Since the parse method is called from the server I don’t any events sent out. Else I would end up in an infinite event loop.
Does it mean that you run Gantt on the server by using the Gantt for Node.js version?
If not, and you trigger the parse method by updating something on the server, you need to implement a custom solution to make sure that you don’t get the infinite loop.
Gantt is a client-side library, and right now, there is no built-in feature to make it work in the multiple user environment, but it is possible to implement a custom solution.
There is a demo that can help you to start: https://files.dhtmlx.com/30d/527f6eaa401559df691c0d71b4a91a46/gantt_with_live_update.zip
Get a guaranteed answer from DHTMLX technical support team
under the most suitable support plan