adds a new task
task | NewTask | the task object |
parent | string | number | optional, the parent's id |
index | number | optional, the position the task will be added into (0 or greater) |
string| number | the task's id |
var taskId = gantt.addTask({
id:10,
text:"Task #5",
start_date:"02-09-2013",
duration:28
}, "project_2", 1);
If you set the index parameter with the value from 0 and greater, a task will be added to the specified position in the branch. Otherwise, the task will be added to the end of the tasks' branch.
The method invokes the onBeforeTaskAdd and onAfterTaskAdd events.
Note, if you don't want to save task in case, for example, the user clicks the "Cancel" button in the lightbox, use the createTask method and the onTaskCreated event that this method invokes.
A quite easy way to prevent users from adding sub-tasks to specific tasks is to hide the 'Add' button through CSS.
gantt.templates.grid_row_class = function( start, end, task ){
if ( task.$level > 1 ){
return "nested_task"
}
return "";
};
.nested_task .gantt_add{
display: none !important;
}
Related sample: Predefined Project Structure