Hello,
I'm using the Kendo Angular Gantt chart, using flat binding since that's how the data is stored in my database. A lot of the example code for editing tasks, dragging tasks, etc. rely on using the subtasks property on the Task to determine if the parent start/end dates or the completionRatio needs to be updated.
What is the best way to calculate the new start/end date or completionRatio when using flat binding? I know that I could make a call to the database to calculate this, but would prefer to calculate this locally if possible. Thanks!
Example: see dataItem.completionRatio calculation below.public onDragEnd(e: TaskDragEvent, gantt: GanttComponent): void {
const originalItem = { ...e.item.dataItem };
const editedItem = {
...originalItem,
start: e.start,
end: e.end,
completionRatio: e.completionRatio,
};
const taskFormGroup = this.createFormGroup(editedItem);
if (!taskFormGroup.valid) {
// You can notify the user that the edited item is invalid.
return;
}
// Update the edited item
Object.assign(e.item.dataItem, {
start: e.start,
end: e.end,
completionRatio: e.completionRatio,
});
// Edit the ancestor items accordingly if necessary
if (this.anyChanged(originalItem, editedItem)) {
let currentItem = e.item.parent;
while (currentItem) {
const dataItem = currentItem.dataItem;
const subtasks = dataItem.subtasks;
dataItem.completionRatio =
subtasks.reduce((acc, curr) => acc + curr.completionRatio, 0) /
subtasks.length;
dataItem.start = new Date(Math.min(...subtasks.map((t) => t.start)));
dataItem.end = new Date(Math.max(...subtasks.map((t) => t.end)));
currentItem = currentItem.parent;
}
}
gantt.updateView();
}