Skip to main content

provide-data

Description

Provides new data for a branch

You should call this action to provide data for a branch.

Usage

"provide-data": ({
id: string|number,
data: {
tasks?: [],
links?: []
};
}) => boolean|void;

Parameters

  • id - (required) the ID of the task for which data should be provided
  • data - (required) new data provided for a branch (the tasks and links arrays)
info

For handling the actions you can use the Event Bus methods

Example

In the example below we listen to the request-data action with the help of the api.on() method, fetch the tasks branch data from the server and parse to the component calling the provide-data action.

<script>
import { Gantt } from "wx-svelte-gantt";

const server = "https://some-server";

let api;
let tasks = [];
let links = [];

Promise.all([
fetch(server + "/tasks")
.then(res => res.json()),
fetch(server + "/links").then(res => res.json()),
]).then(([t, l]) => {
tasks = t;
links = l;
});

function init(api) {
api.on("request-data", ev => {
Promise.all([
fetch(server + `/tasks/${ev.id}`)
.then(res => res.json()),
fetch(server + `/links/${ev.id}`).then(res => res.json()),
]).then(([tasks, links]) => {
api.exec("provide-data", {
id: ev.id,
data: {
tasks,
links,
},
});
});
});
}
</script>

<Gantt bind:api {init} {tasks} {links} />

Related articles: How to access Gantt API