finds a task by the specified criteria

Array <Task> getTaskBy(string|function propertyName, [string|number|array propertyValue,object types] );
propertyNamestring|functionthe name of the property to match, or a filter function
propertyValuestring|number|arraythe property value
typesobjectan object with types of the tasks which should be returned
Array <Task>array of task objects


// simple search
const userTasks = gantt.getTaskBy("user_id", [5]);
// (task: object) => boolean
let userTasks = gantt.getTaskBy(function(task){
   return task.user_id == 5 || !task.user_id;
userTasks = gantt.getTaskBy(task => task.user_id == 5);

Related samples

  • The method can be used for selecting tasks by the property value, e.g. find tasks of a specific user, find completed tasks, etc.
  • gantt.getTaskBy(propertyName, propertyValue) uses loose equality check ("double equals", ==)
  • The result of gantt.getTaskBy(propertyName, propertyValue) can be cached by gantt, thus this overload can work faster than gantt.getTaskBy((task: object) => boolean)

By default gantt.getTaskBy() returns only task and milestone items that match the criteria, while project items are omitted.

To select records of all types, use the following value of the third parameter:

gantt.getTaskBy("progress", 1, { task: true, project: true, milestone: true });

To return items of only a specific type, specify the type value in the third parameter:

gantt.getTaskBy("progress", 1, { project: true})
See also
Change log

the types parameter was added in v8.0

Back to top