SVAR Gantt is data-agnostic: you load tasks and links from any source and apply changes back to the server through the event system. TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/svar-widgets/gantt/llms.txt
Use this file to discover all available pages before exploring further.
@svar-ui/gantt-data-provider package provides a ready-made RestDataProvider class that implements this for standard REST APIs.
Raw fetch approach
For full control, fetch initial data yourself and wire up therequest-data event for lazy-loaded subtrees:
Date strings from the server must be converted to
Date objects before passing them to Gantt. Call new Date(item.start) for start, end, base_start, and base_end fields.RestDataProvider
RestDataProvider handles both data loading and automatic persistence of Gantt actions (add, update, delete tasks and links) back to the server.
Installation
Constructor
| Parameter | Type | Description |
|---|---|---|
url | string | Base URL of the REST API |
config.batchURL | string | Relative URL for batch requests (enables batch mode) |
getData()
Fetches tasks and links from the server:- Without an
id— fetches all root-level data (GET /tasks,GET /links). - With an
id— fetches the subtree for that task (GET /tasks/:id,GET /links/:id).
getData() calls parseDates() internally, so start, end, base_start, and base_end fields are already converted to Date objects.
Wiring to Gantt
<script>
import { RestDataProvider } from "@svar-ui/gantt-data-provider";
import { Gantt, ContextMenu, Editor } from "@svar-ui/svelte-gantt";
const restProvider = new RestDataProvider(
"https://your-api.example.com"
);
</script>
<script>
let tasks = $state();
let links = $state();
restProvider.getData().then(({ tasks: t, links: l }) => {
tasks = t;
links = l;
});
</script>
Call
api.setNext(restProvider) so the provider intercepts every Gantt action and persists it to the server. Also handle request-data for lazy subtrees:<script>
function init(api) {
api.setNext(restProvider);
api.on("request-data", ev => {
restProvider.getData(ev.id).then(({ tasks, links }) => {
api.exec("provide-data", {
id: ev.id,
data: { tasks, links },
});
});
});
}
</script>
<ContextMenu {api}>
<Gantt bind:this={api} {init} {tasks} {links} />
</ContextMenu>
<Editor {api} />
Full example
Expected REST API endpoints
RestDataProvider maps Gantt actions to the following HTTP endpoints:
Tasks
| Method | URL | Triggered by |
|---|---|---|
GET | /tasks | getData() (initial load) |
GET | /tasks/:id | getData(id) (subtree load) |
POST | /tasks | add-task |
PUT | /tasks/:id | update-task, move-task, copy-task |
DELETE | /tasks/:id | delete-task |
Links
| Method | URL | Triggered by |
|---|---|---|
GET | /links | getData() (initial load) |
GET | /links/:id | getData(id) (subtree load) |
POST | /links | add-link |
PUT | /links/:id | update-link |
DELETE | /links/:id | delete-link |
Date serialisation
When sending data to the server,Date objects are serialised using the format yyyy-MM-dd HH:mm:ss.
Batch mode
When multiple changes happen in quick succession (e.g. moving several tasks), batch mode groups them into a single HTTP request to reduce network overhead. Enable it by providingbatchURL in the config:
POST /batch request with this body shape:
parseDates() reference
RestDataProvider.parseDates() iterates over a task array and converts the following string fields to Date objects in place:
| Field | Converted |
|---|---|
start | Always |
end | If present |
base_start | If present |
base_end | If present |
getData() calls this automatically. You only need to call it manually if you bypass getData() and fetch tasks with your own fetch calls.