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

function getData() {
return Promise.resolve([]);
}

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

import { useState, useEffect, useRef } from "react";
import { Gantt } from "wx-react-gantt";
import { RestDataProvider } from "wx-gantt-data-provider";

const GanttComponent = () => {
const url = "https://some_backend_url";
const server = new RestDataProvider(url);
const [tasks, setTasks] = useState([]);
const [links, setLinks] = useState([]);
const apiRef = useRef();

useEffect(() => {
server.getData().then(data => {
setTasks(data.tasks);
setLinks(data.links);
});
}, []);

return (
<Gantt
tasks={tasks}
links={links}
apiRef={apiRef}
/>
);
};

export default GanttComponent;

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:

const 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: