Skip to main content

group-tasks

PRO

The functionality is available in PRO Edition only

Description​

Fires when grouping tasks by a specified field

Usage​

"group-tasks": ({
field: string,
taskHierarchy?: boolean,
resourceHierarchy?: boolean,
multipleResources?: boolean,
ungrouped?: false | "top" | "bottom",
resolver?: (task: ITask) => any,
}) => boolean | void;
info

For handling the actions you can use the Event Bus methods. Returning false from the action handler will block the action (see Preventing actions)

Parameters​

The callback of the group-tasks action can take an object with the following parameters:

  • field - (required) the field to group tasks by; use "resource" to group by assigned resources, or any task field name (e.g., "status", "priority")
  • taskHierarchy - (optional) if true, preserves the task parent/child structure within each group; Default: false
  • resourceHierarchy - (optional) if true, shows the resource hierarchy (teams and people) within resource groups; applies only when field is "resource"; Default: true
  • multipleResources - (optional) controls how tasks assigned to multiple resources are displayed: if false, the task appears under each assigned resource separately; if true, the task appears once under a combined group label (e.g., "Alice, Bob"); applies only when field is "resource"; Default: false
  • ungrouped - (optional) controls placement of tasks that have no value for the grouping field: false hides them, "top" places them above all groups, "bottom" places them below all groups; Default: "bottom"
  • resolver - (optional) a custom function (task: ITask) => value to extract the group value from a task; overrides the default task[field] lookup; not applicable when field is "resource"

Example​

Use the api.exec method to trigger the action:

import { getData } from "./common/data";
import { Gantt } from "@svar/react-gantt";
import { useRef } from "react";

function App() {
const data = getData();
const api = useRef(null);

const init = ganttApi => {
api.current = ganttApi;
};

const groupByResource = () => {
api.current.exec("group-tasks", { field: "resource" });
};

return (
<Gantt
tasks={data.tasks}
links={data.links}
scales={data.scales}
resources={data.resources}
assignments={data.assignments}
init={init}
/>
);
}

Prevent grouping​

You can intercept the action and return false to block it:

api.intercept("group-tasks", ev => {
if (!allowGrouping) return false; // prevents grouping
});

Related articles: