Probably overlooking something simple, but haven't been able to work it out yet via the docs or searching this forum.
I have a Gantt Chart in a custom component that I imported from GitHub - frappe/gantt: Open Source JavaScript Gantt
The chart looks like this:
I am trying to add some code to send the changes made in the chart back to my retool app (and in future- save to MySQL), to do this I use this JS:
here's the iframe code for Gantt chart:
<script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/frappe-gantt/0.6.1/frappe-gantt.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/frappe-gantt/0.6.1/frappe-gantt.css">
<style>html {
margin: -10px;
}</style>
<svg id="gantt"></svg>
<script>
window.Retool.subscribe(function (model) {
var gantt = new Gantt('#gantt', model.tasks, {
on_date_change: (task, start, end) => {
save(end);
},
language: 'en'
});
});
async function save(data) {
window.Retool.modelUpdate({ 'changed': data });
window.Retool.triggerQuery('saveChange');
}
</script>
it uses this model
{
tasks: {{ getTasks.data }}
}
here are some sample tasks data:
{
"tasks": [
{
"id": "task-1",
"name": "design a table",
"start": "2023-10-25T00:00:00.000Z",
"end": "2023-10-26T00:00:00.000Z",
"progress": 10,
"dependencies": "task-1",
"custom_class": "bar-milestone"
},
{
"id": "task-2",
"name": "import node data",
"start": "2023-10-26T00:00:00.000Z",
"end": "2023-10-27T00:00:00.000Z",
"progress": 10,
"dependencies": "task-1",
"custom_class": "bar-milestone"
}
]
}
this almost works - when I change a task end date on the Gantt - I see the console log the message:
"save this change Thu Oct 26 2023 00:00:00 GMT+0800 (Australian Western Standard Time) Sun Oct 29 2023 23:59:59 GMT+0800 (Australian Western Standard Time"
which is great, HOWEVER, the Gantt chart doesn't persist the change, eg. the task slider returns to the default.
if I comment out the code that saves the data:
//save(end)
now the chart works eg. dragging the task end date persists (it just isn't saved now):
I have tried returning null etc. from the save function, tried setting it to async, I've searched the forums and internet for solutions but I cant get it to work correctly,
Does someone know what I am doing wrong (I know JS but I am new to retool)
these pages got me close:
and, I'll keep looking...