Our state of the art Gantt chart


Post by amandachen »

Hello,

I am trying to create an external "undo" button for the user to undo a task resize.

I am able to get the original end date (prior to resize) from the taskResizeEnd event. Is there a function I can then call to edit the end date of that specific task? Visually, I want the bar to shift back to its original position.


Post by mats »

Have you tried using our built-in undo?

You can update a task by simply setting a new field value:

task.endDate = new Date(2021,4, 13)

Post by amandachen »

Hi Mats, thanks for your reply. What are the differences between the way you suggested and this lifecycle method? https://www.bryntum.com/docs/gantt/#Gantt/model/TaskModel#function-setEndDate


Post by arcady »

The method changes endDate field value and then launches changes propagation that recalculates all the related project data. The method returns a Promise to wait for the propagation completion:

await task.setEndDate(new Date())
// here all the related data changes is applied

Changes propagation will be scheduled automatically when you change endDate.
Son in most of the cases just changing fields is enough.

Yet if you need to get recalculated values right after the change you'll need to wait till recalculation is done. For example:

task.endDate = new Date()
console.log(task.duration) // this will not dump new duration recalculated after endDate change ..since changes propagation is not done yet (it's just scheduled)

You can trigger changes propagation manually to fix the above scenario:

task.endDate = new Date()
await project.commitAsync()
console.log(task.duration) // this will dump new recalculated duration

Or use setEndDate method which will give you the same result and look a bit shorter:

await task.setEndDate(new Date())
console.log(task.duration) // this will dump new recalculated duration

Post by amandachen »

Got it, that makes sense! Thank you!


Post Reply