Our state of the art Gantt chart


Post by s-tech »

How can i add or removed a task or sub task in Gantt chart without destroying the existing Gantt instance when Gantt chart is completely loaded.


Post by mats »

Please study the https://bryntum.com/docs/gantt/api/Gantt/data/TaskStore class, it has add and remove methods. You can see the add method in use in the https://bryntum.com/examples/gantt/advanced/ (Create button)

store.add({ name : 'foo'})

Post by s-tech »

It works perfect for parent task but not for sub-task, so can you also please guide how to add sub-task in a specific parent task after gantt is completely loaded.


Post by tasnim »

To achieve that you need to use apendChild method.
Please check docs : https://bryntum.com/docs/scheduler/api/Core/data/Model#function-appendChild

Here is an example of how you can use it:

gantt.taskStore.getById('11').appendChild({ name: 'foo' });

Best regards,
Tasnim


Post by s-tech »

moreover, how we can add a task or sub task on a specific index in gantt chart.


Post by tasnim »

You can get the whatever taskRecord you want by the getById function

Please check the docs here: https://bryntum.com/docs/scheduler/api/Core/data/Store#function-getById
I also gave an example in my last thread which is this:

gantt.taskStore.getById('11').appendChild({ name: 'foo' });

Best regards,
Tasnim


Post by s-tech »

NO, I'm not asking this. My question is if i get a task index by this function (gantt.taskStore.indexOf(id)) it will return an index on which task is available on Gantt chart, so after that i want to push some other task on that index how can i do that ?

Screenshot 2022-05-18 at 5.03.44 PM.png
Screenshot 2022-05-18 at 5.03.44 PM.png (24.59 KiB) Viewed 246 times

As you see that, I give an ID and it returns the index which i want to use for the next task to add on that index


Post by johan.isaksson »

Hi,

The TaskStore in Gantt is a tree store, inserting at a specific index only makes sense in a flat store. What you probably want to do is add to the parent of the task, adjacent to the task. Try something like this:

const task = gantt.taskStore.getById(...);
task.parent.insertChild(newTask, task);

Docs for insertChild here: https://bryntum.com/docs/gantt/api/Core/data/Model#function-insertChild

Best regards,
Johan Isaksson

Post by s-tech »

I want to add a parent task or a sub-task on a specific index like insert at index n, for example, gantt is loaded and I want to add a new task at index 2 or Nth index.
Example:
Take the example of array [a , b , c , d , e] . I want to add a new letter "f" to this array at index 2 so the new array will be
[a , f , b , c , d , e]. The same experience i want in gantt chart.


Post by johan.isaksson »

You could use parent.insertChild(newTask, parent.children[3]) to insert at a specific index in a parent task

Best regards,
Johan Isaksson

Post Reply