getTaskBy
Description
Finds a task by the specified criteria
getTaskBy: (propertyName: string | GanttCallback, propertyValue?: string | number | boolean | any[], types?: any) => Array<Task>
Parameters
propertyName- (required) string | function - the name of the property to match, or a filter functionpropertyValue- (optional) string | number | boolean | array - the property valuetypes- (optional) object - an object with types of the tasks which should be returned
Returns
tasks- (Array <Task>) - array of task objects
Example
// 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
Details
- 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 thangantt.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})
Related API
Change log
- the types parameter was added in v8.0