Adding new task to beginning of the gantt chart

Hi there,

is there a way (either with the UI, or the database) to add a new first task to the gantt chart? We have a system set up so that we redraw the gantt chart’s based off of a template, and I want to add tasks to the beginning of the template. Is this possible, or is my only option to redraw the entire chart?

Hi,
adding new task always invokes redrawing the whole chart in order to update absolute positioned elements.
Can you please clarify what exactly the issue is? Do you want to avoid the internal call of gantt.render/gantt.refreshData after calling gantt.addTask (which is not possible due to internal implementation of the component), or did you mean something else?

I used ‘redrawing’ incorrectly.

Say I have a large gantt chart that is drawn out like this:

Parent 1
Task 1.1
Task 1.2
Task 1.3
Parent 2
Task 2.1
Task 2.2
Parent 2
Task 3.1
Task 3.2

That goes on and on over 100 tasks in my project - and then my company says "We have a new Parent 1, the existing Parent 1 should now be Parent 2, So i want to add a task to the very beginning of the project.

Does that make sense? I’m having no issue in the way the gantt chart is rendering right now, just seeing if there was a way to manipulate the data / a feature I’m missing

Depending how do you want to do it, there may be two possible solutions

a) you can make changes on a backend either to database directly or via data access wrappers you use. Basically, gantt tasks table is a tree structure, so in order to add new top level to your project you need to:

  1. you find the current root task (Parent 1), it has either a empty or 0 value of the ‘parent’ column.
  2. you insert new task with the name “Parent 1” and empty parent and get it’s id - so at this moment your project will have two root items
  3. update the old root you retrieved at step (1) - change the description to “Parent 2” and change it’s ‘parent’ column value to the id of the new root task you inserted at step (2). That will move the whole project tree to the new parent.
  • so all can be done in three sql queries - select, insert and update.

b) It’s pretty same on the client:

  1. you add task to the top level using gantt.addTask
  2. and make old root task its child docs.dhtmlx.com/gantt/api__gantt_movetask.html

Is that what you mean?

This information will help a lot! Thank you. I need to play around with it, but I hadn’t seen the gantt.movetask.

Thanks again