returns the type of a task

string getTaskType(object task);


taskobjectthe task object


stringthe type of the task


var type = gantt.getTaskType(gantt.getTask(12));

  • If task.type property is defined and not empty, the value of this property will be returned.
  • Otherwise, the value of gantt.config.types.task will be returned instead.

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
  • Items that don't have the type property won't meet this condition. This would be incorrect, because such items have the task type by default.

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:

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:
    case gantt.config.project:
    case gantt.config.milestone:
See also
  • Articles
  • Back to top