Skip to main content

request-data

Description​

Fires when data for a lazy task branch is requested

Gantt 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 requested
  • nested - (optional) true if the branch is opened by open-task with nested: 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 setup>
import { ref } from "vue";
import { RestDataProvider } from "@svar-ui/gantt-data-provider";
import { Gantt } from "@svar-ui/vue-gantt";
import { Button } from "@svar-ui/vue-core";

const restProvider = new RestDataProvider("https://some_backend_url");

const tasks = ref([]);
const links = ref([]);
const api = ref();

restProvider.getData().then(data => {
tasks.value = data.tasks;
links.value = data.links;
});

function init(ganttApi) {
api.value = ganttApi;
api.value.on("request-data", ({ id, nested }) => {
console.log(
"Data request for: " +
id +
(nested ? " with nested parameter" : "")
);
});
}

function expandTask() {
api.value.exec("open-task", { id: 1, mode: true, nested: true });
}
</script>

<template>
<Button type="primary" :onclick="expandTask">Expand task</Button>
<Gantt :init="init" :tasks="tasks" :links="links" />
</template>

Related sample:

Related articles: