request-data
Description
Fires when data for a lazy task branch is requestedGantt triggers this action only from the open-task action with mode: true, for a task that has lazy: true and no loaded children.
To pass the loaded data to Gantt, use the provide-data action. See also Dynamic data loading.
Usage
"request-data": ({
id: string | number,
nested?: boolean
}) => boolean | void;
Parameters
The callback of the request-data action can take an object with the following parameters:
id- (required) the task ID for which data is requestednested- (optional) true if the branch is opened byopen-taskwithnested: true. The handler should load the whole subtree of the task, not only its direct children
info
For handling the actions you can use the Event Bus methods
Example
<script>
import { RestDataProvider } from "@svar-ui/gantt-data-provider";
import { Gantt } from "@svar-ui/svelte-gantt";
import { Button } from "@svar-ui/svelte-core";
const restProvider = new RestDataProvider("https://some_backend_url");
let tasks = $state([]);
let links = $state([]);
let api = $state();
restProvider.getData().then(data => {
tasks = data.tasks;
links = data.links;
});
function init(ganttApi) {
api = ganttApi;
api.on("request-data", ({ id, nested }) => {
console.log(
"Data request for: " +
id +
(nested ? " with nested parameter" : "")
);
});
}
function expandTask() {
api.exec("open-task", { id: 1, mode: true, nested: true });
}
</script>
<Button type="primary" onclick={expandTask}>Expand task</Button>
<Gantt {init} {tasks} {links} />
Related sample:
Related articles: