Discuss anything related to web development but no technical support questions


Post by sandippatel »

Hello Support

I am using new version on Bryntum Gantt with React. I am curious to know that is it possible to add task or project dynamically without using "Create" button. I want to achieve functionality where user could have separate field where he could enter task name and when click on add, it could add in gantt chart.

Is this possible?

Thanks


Post by arcady »

To add a task dynamically you just add a record to the task store:

gantt.taskStore.add({ name : 'New task', duration : 1 })

And a project is just an instance of the ProjectModel class.
So you can create an instance in the runtime and assign it to the gantt. Something like this for example:

const project = new ProjectModel({
    startDate : new Date(),
    tasksData : [...],
    dependenciesData : [...],
    ...
});

gantt.project = project;

Post by sandippatel »

Thank. any example I can see in demo? I mean in example folder where I can look into it?


Post by arcady »

Example of adding a task?
Check Gantt/examples/react/javascript/advanced/src/containers/Panel.js file. These lines add a task dynamically:

                            async onAction() {
                                const added = gantt.taskStore.rootNode.appendChild({ name : 'New task', duration : 1 });

Post by sandippatel »

So can I use this from another react component? I am calling this panel from my react component and I have one textbox in that component so when I hit "Add" it could add task in chart. so for this do I need to expose this so I any component could use?

Sorry I am learning both react and gantt so asking silly questions.


Post by arcady »

You have "Add" button as far as I understand if that button calls the code I mentioned it will add a task


Post Reply