Smart UI Components & Libraries – Grid, Scheduler, Gantt, Kanban for Angular, React, Next.js, Vue, Blazor, JavaScript › Forums › Gantt › Any community tips or tricks for: Gantt?
- This topic has 1 reply, 2 voices, and was last updated 1 month, 2 weeks ago by
Markov.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
October 10, 2025 at 6:06 am #113089
alex.morris22
ParticipantCan I use Smart Gantt with a REST API?
October 14, 2025 at 6:51 am #113097Markov
KeymasterHi,
Yes, this is possible. As a solution look at the following code which fetches data from a server and data binds the Gantt chart to it.
// assume we have <smart-gantt-chart id="gantt"></smart-gantt-chart> in HTML const gantt = document.getElementById('gantt'); // Function to map server model → Gantt model function mapServerToGantt(serverTasks, serverLinks) { return { // the Gantt expects tasks + links (or inside dataSource) tasks: serverTasks.map(t => ({ id: t.id, label: t.name, dateStart: t.startDate, dateEnd: t.endDate, progress: t.progress, // etc. })), links: serverLinks.map(l => ({ id: l.id, source: l.fromTaskId, target: l.toTaskId, type: l.type // e.g. “finish-to-start” })) } } // Initial load fetch('/api/tasks') .then(r => r.json()) .then(data => { const mapped = mapServerToGantt(data.tasks, data.links); gantt.dataSource = mapped; }) .catch(err => { console.error('failed load tasks', err); }); // Listen for changes gantt.addEventListener('onTaskChanged', (e) => { const changed = e.detail; // depending on library’s event payload // you’ll have to inspect the event shape from the api docs fetch(<code>/api/tasks/${changed.id}</code>, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ startDate: changed.dateStart, endDate: changed.dateEnd, progress: changed.progress }) }).then(/* … */).catch(/* … */); }); // Similar for link-add / link-delete, etc. gantt.addEventListener('onLinkAdded', (e) => { const link = e.detail; fetch('/api/links', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ source: link.source, target: link.target, type: link.type }) }).then(/* … */).catch(/* … */); });Hope this helps.
Best regards,
MarkovSmart UI Team
https://www.htmlelements.com/ -
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.