Insert Task on Select Index


#1

Hi,
I’m trying to Add a Task as a sibling of a selected task, but is not getting anywhere. I did try to move the new task on this event onAfterTaskAdd but it seems to call multiple times my api. one for update and one for order.

Anyone knows what the best practice on adding a task below a selected task?

Thanks and more power


#2

I was provided with this solution but in Angular is not seem to be found. Any idea?

const columns = [
{name: “text”, label: “Task”, tree: true, width: “150”, min_width: 150, resize: true, editor: textEditor},

{name:“add_custom”, label:"", width:44, template: function (task){
return “+”
}},
]

function addSibling(id:any){
  const selectedTask = gantt.getTask(id);
  const newId = 0;
  var index = selectedTask.$index;
  gantt.createTask({id: newId, start_date:gantt.getState().min_date, duration: 1},selectedTask.parent, index);
}

#3

Hello Ricky,
The function works correctly if I attach it to the gantt object
Here is an Angular 9 demo:
https://files.dhtmlx.com/30d/54513752f28239e4a9ef1f1930054039/angular9+grid_buttons-add_tasks-7.0.1-GPL.zip


#4

Hi,

Thanks this works indeed,

I am however stucked in mapping the start date for gantt. It’s seems it is not mapping correctly even with a valid date that is provided.

Please refer to the attached image.

As you could see Sitework task has a start date of ‘2020-11-05T07:56:00.58’ however the gantt is showing this differently’

This is how I map the field in gantt column

const columns = [

{name: “text”, label: “Task”, tree: true, width: “150”, min_width: 150, resize: true, editor: textEditor},
{name: “start_date”, label: “Start”, align: “center”, width:80 , min_width:80, resize: true},

]

Really appreciate your help since this is what stoping us in continuing the evalution period.

Thanks


#5

Hello Ricky,

Probably, it happens because of the wrong gantt.config.date_format or gantt.config.xml_date parameters:
http://snippet.dhtmlx.com/5/e95b2c8e9

Or it can happen if you turn on the auto-scheduling feature:
http://snippet.dhtmlx.com/5/729248972

If you have a different use case, it can be related to something else, but it is hard to suggest what might be wrong as I don’t see your code. In that case, please, reproduce the issue in the snippet, then click on the “Share” button and send me the link:
https://snippet.dhtmlx.com/38ee1b370

Or send me a ready demo with all the necessary Javascript and CSS files so that I can reproduce the issue locally.