api.getState()
Description
Gets the state object that stores current values of most Gantt propertiesYou can apply the method to get the state of tasks, links, columns, scales, etc. See the parameters of the returned object below.
Usage
api.getState(): object;
Returns
The method returns an object with the following parameters:
{
tasks: array,
links: array,
start: Date,
end: Date,
columns: false | array,
scales: array,
scaleHeight: number,
cellWidth: number,
cellHeight: number,
lengthUnit: string,
durationUnit: string,
taskTypes: array,
zoom: boolean | array,
selected: number | string,
activeTask: number | string,
autoScale: boolean,
scrollTop: number,
scrollLeft: number,
// --- PRO FEATURES ---
history: object, // PRO
undo: boolean, // PRO
baselines: boolean, // PRO
markers: array, // PRO
unscheduledTasks: boolean, // PRO
splitTasks: boolean, // PRO
criticalPath: object, // PRO
schedule: object, // PRO
projectStart: Date, // PRO
projectEnd: Date, // PRO
};
Gantt properties detailed description you can find here: Gantt properties overview.
State-only properties
history PRO feature
history is an object with the number of operations for each undo/redo action:
history: {
undo: number,
redo: number,
};
area
Represents the visible horizontal time range of the Gantt chart.
area: {
start: number, // timestamp (ms) of the first visible date on screen
end: number, // timestamp (ms) of the last visible date on screen
from: number // horizontal scroll offset in pixels from the start of the timeline
};
scrollTop
Represents the vertical scroll position:
scrollTop: number;
scrollLeft
Represents the horizontal scroll position:
scrollLeft: number;
Example
<script>
import { getData } from "./common/data";
import { Gantt } from "@svar-ui/svelte-gantt";
const data = getData();
function init(api){
const { tasks, links } = api.getState();
console.log(tasks);//output the state of tasks
console.log(links);//output the state of links
}
</script>
<Gantt tasks={data.tasks} links={data.links} {init} />
Related articles: