Skip to main content

getData()

Description

Gets a promise with an array of tasks and links objects
info

The getData() method is a part of the RestDataProvider service intended for working with a server

Usage

getData(): Promise<[]>

Response

The getData() method sends a request to the server by the GET method and returns a promise with data on links and tasks. For the examples of returned objects, see tasks and linksю

Examples

<script>
import { Gantt } from "@wx/svelte-gantt";
import { RestDataProvider } from "@wx/gantt-data-provider";

const url = "https://some_backend_url";

const server = new RestDataProvider(url);
let api;
let tasks, links;

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

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

parseDates() method

Description: getData() applies the parseDates() method to parse dates (start, end, base_start, base_end from tasks) to Date object (as new Date(string)).

Usage:

parseDates(task) => task

If you need to change the parsing method, you can redefine it as in the example below: create a new class for RestDataProvider, set the required parsing method using the parseDates() method, and then apply this new class for RestDataProvider.

class MyProvider extends RestDataProvider{
parseDates(task){
// parse dates by method you like
return task;
}
}

const restProvider = new MyProvider(serverUrl);

Related articles: