I'm building a Gantt Chart with dhtmlx-gantt that contains parent and child tasks.
- A parent task can be a dependent on another parent or child task
- A child task can be dependent on another child or parent task
- Tasks can have multiple dependencies
- A dependent task can only begin once it's ruling task is complete
If a dependency is added to a task under Parent A to Parent C, this will move the shift the start date to all tasks in Parent C, like so
Here's how my data is structured
const tasks = [ { id: 'parent-a', text: 'Parent A', duration: null }, { id: 'child-a-1', text: 'Child 1', parent: 'Parent A', duration: 5 }, { id: 'child-a-2', text: 'Child 2', parent: 'Parent A', duration: 5 }, // ... ] const dependencies = [ { id: 1, source: 'child-a-1', target: 'child-a-2' }, { id: 1, source: 'parent-b', target: 'parent-c' }, // ... ] To calculate the start date for each task, loop through each task and set the date dynamically based on the duration of the task
let startDate = new Date() tasks.forEach((task, i, array) => { const correspondingDependency = dependencies.find(d => d.id === task.id) if (correspondingDependency) { array[i].start_date = new Date(startDate.setDate(startDate.getDate() + duration)) } }) The problem with this method is it won't update any start_dates for prior tasks if a dependency is found at the end of the dependencies array (i.e., child-c-1 is dependent on child-a-3)
I feel like I may need to use recursion here, but not quite sure. Hope this all makes sense - any help is appreciated

