I am trying to add new task in gantt in between instead of adding in last in activity log. When user clicks on any tasks he gets the option “add above” and the task gets added above the clicked task. I am facing issue in adding task above the existing task.
Hello,
One of the option is to create a custom button in the grid which will create a new task above the clicked one. You can add a new object to the columns of the grid with the template
attribute:
https://docs.dhtmlx.com/gantt/api__gantt_columns_config.html ;
Here, you can create a button with data-action
attribute. Once the button is created, use onTaskClick
event to track clicks on it with the help of e.target.closest
property. You can check the article about it:
https://docs.dhtmlx.com/gantt/api__gantt_ontaskclick_event.html ;
To create a new task above another one, use the createTask
method with the following parameters:
gantt.createTask(null, task.parent, index);
Where null
is a new task’s object, task.parent
is the clicked task, and index
is a position of the clicked task, which can be retrieved using gantt.getTaskIndex(task.id)
, so a new task will replace the previous.
Related articles:
https://docs.dhtmlx.com/gantt/api__gantt_createtask.html ;
https://docs.dhtmlx.com/gantt/api__gantt_gettaskindex.html ;
Please check the following snippet:
https://snippet.dhtmlx.com/6vagjih0
Hello,
As I see from your screenshot, you are using something like pop up menu, where you have an option to add a new task above. I tried to reproduce it by using Quick Info
extension:
https://docs.dhtmlx.com/gantt/desktop__quickinfo_ext.html ;
I added a custom button to the quick info and attach the function which creates a new task above another one:
gantt.config.quickinfo_buttons = ["icon_delete", "add_above_btn"];
gantt.locale.labels["add_above_btn"] = "Add above";
gantt.$click.buttons.add_above_btn = function (id) {
let task = gantt.getTask(id);
let index = gantt.getTaskIndex(task.id);
gantt.createTask(null, task.parent, index);
return true;
};
Please check the following demo with Quick Info
:
https://files.dhtmlx.com/30d/896c751d2238e63c61053703c12b803d/react+gantt+quick_info.zip
If it doesn’t help you, could add your configuration in the demo above and sent me an updated demo.