api.getTask(id)
Description
Gets an object with the task configurationUsage
api.getTask(id): object;
Parameters
id
- the id of a task
Returns
The method returns an object with the tasks parameters:
{
id: string|number,
start: Date,
end?: Date,
duration?:number,
text?: string,
progress?: number,
parent?: string|number,
type?: "task" | "summary" | "milestone"|any,
open?:boolean,
lazy?:boolean,
base_start?: Date,
base_end?: Date,
base_duration?: number
}
Example of the object that is returned:
{
id: 3,
start: Thu Mar 05 2020 00:00:00 GMT+0300 (Moscow Standard Time),
end: Sat Mar 07 2020 00:00:00 GMT+0300 (Moscow Standard Time),
text: 'Task 3',
progress: 6,
type:"summary",
duration:2,
parent:0
}
Example
The example shows how to output to console data on the task with "id:3".
import { useEffect, useRef } from "react";
import { getData } from "../data";
import { Gantt } from "wx-react-gantt";
const GanttComponent = () => {
const data = getData();
const apiRef = useRef(null);
useEffect(() => {
if (apiRef.current) {
const task = apiRef.current.getTask(3);
console.log("Task:", task);
}
}, [apiRef.current]);
return (
<Gantt
apiRef={apiRef}
tasks={data.tasks}
links={data.links}
scales={data.scales}
/>
);
};
export default GanttComponent;
Related articles: