returns the type of a task
task | Task | the task object |
string | the type of the task |
var type = gantt.getTaskType(gantt.getTask(12));
Since the task.type property is optional, you have to take into account that it may be empty when you check the type of the task in code, e.g.
// BAD:
if (task.type === gantt.config.types.task){
// code specific for task items
}
Instead, you can either add a condition for empty values:
// GOOD:
if (!task.type || task.type === gantt.config.types.task){
// code specific for task items
}
Or use the getTaskType method:
// EVEN BETTER:
if (gantt.getTaskType(task) === gantt.config.types.task){
// code specific for task items
}
The code will work for all items that have a type specified explicitly, as well as for items that have a default type assigned by the Gantt internal logic.
The following method can be used as a safe way for getting task types, in order to write the same conditions for all types of items, and avoid potential bugs with incorrect type detection:
switch (gantt.getTaskType(task)){
case gantt.config.task:
break;
case gantt.config.project:
break;
case gantt.config.milestone:
break;
}