Hello Sonali,
I have this version running in production with same code but with Aura components
Now I am migrating these things to LWC so Wondering why it is creating problem in LWC?
Probably, you tried the Trial version there. It has all Enterprise features including the feature for creating new Gantt instances on the page.
You mean something like this from documentation
Yes, you can comment these strings:
Receiving Error at this line
console.log(‘window.Gantt’, window.Gantt); //Undefined
const gantt = window.Gantt.getGanttInstance();
So that it looks like this:
//console.log(‘window.Gantt’, window.Gantt); //Undefined
//const gantt = window.Gantt.getGanttInstance();
But you will need to manually reset the Gantt configuration and detach the events when you switch to another page.
I am new to this library so haven’t understood this comment here!
Please share if you some code snippets for LWC.
To clear the data, you need to use the clearAll
method:
https://docs.dhtmlx.com/gantt/api__gantt_clearall.html
To load the data, you need to use the parse
or load` method:
https://docs.dhtmlx.com/gantt/api__gantt_parse.html
https://docs.dhtmlx.com/gantt/api__gantt_load.html
When you load the page with Gantt, you need to save the event IDs the following way:
const onTaskClick =
gantt.attachEvent('onTaskClick', (id) => {
gantt.message(`onTaskClick: Task ID: ${id}`);
return true;
}, '');
eventIDs.push(onTaskClick);
When you switch to another page, you need to manually detach events by using the IDs that you saved in an array:
eventIDs.forEach(event => gantt.detachEvent(event));
eventIDs = [];
That approach is mentioned here:
https://docs.dhtmlx.com/gantt/api__gantt_detachallevents.html
Apart from that, probably, you will need to do something else, but I didn’t test all possible scenarios with that approach.
Unfortunately, I don’t have the code for LWC, but I can show the approach in the following snippet:
http://snippet.dhtmlx.com/5/a39804820
When you click on the Recreate Gantt
, Gantt will initialize, load tasks, and attach the events. If you destroy Gantt, the events will be detached.