I am working on an integration of Gantt with Salesforce and I am having a problem filtering tasks. Each time I apply filters and render the Gantt(with filtered tasks), I am having to reinitialize the Gantt(causing multiple instances to be created). This, in turn, causes issues while editing tasks in the light box. Each time I click to open a task, lightboxes equalling the number of instances created so far get triggered and opened. So, editing of tasks are rendered not possible. I have tried the following workarounds, but none of them seem to respond.
- Rerendering the Gantt
- Checking if multiple instances of gantt are created with a flag variable and only parsing existing data
- Attempting to use clearAll() to clear existing Gantt data
- Using destructor to destroy existing instances.
- Attaching events only if gantt instance has been newly created.
How do we retrieve exisitng Gantt instances? Is it possible to isolate creating the Gantt instances and parsing it multiple times?
If you want to filter tasks with the
onBeforeTaskDisplay event handler, you don’t need to reinitialize Gantt. You only need to call the
render method to repaint the changes:
Here is a simple example of how it works:
Also, when you reinitialize Gantt, the new instance is not created. That should happen only if you call the code that includes creating a new Gantt instance. For example:
Gantt instance is not changed
A new Gantt instance is created:
gantt = Gantt.getGanttInstance();
If you filter tasks by changing the data on the server, then you parse only that data, you also don’t need to reinitialize Gantt. You only need to use the
clearAll method to remove existing tasks in the browser and use the
load methods to load new tasks.
Thank you for the response. I would like to know how we can retrieve an existing Gantt instance. Currently we are using the trial version of DHTMLx Gantt. Our code to initialize Gantt, parse and display it is given below.
const root = this.template.querySelector(’.thegantt’)
const filters = this.template.querySelector(’.messageClass’)
root.style.height = this.height + “px”
const gantt = window.Gantt.getGanttInstance()
var result = __gantt__setup.parseData((this.myList.length ? this.myList : ))
After applying filters, we are calling the above snippet to repaint the gantt as the gantt.render() is not effecting a change. In doing so, we are typically calling Gantt.getGanttInstance() each time the filter is applied. Will this particular logic work with Standard Edition(I understand Gantt.getGanttInstance() can be called to create multiple instances only in the Professional and Enterprise editions) ?
In this part of the code, you are creating a new Gantt instance each time. So, its settings, event handlers, and loaded data are reset.
It seems that you filter tasks by modifying the array with the data and then giving it to Gantt. Usually, you only need to call the
parse methods for that:
But if you switch between the tabs/views, the Gantt instance doesn’t change. In that case, you will need to create a new Gantt instance, or manually reset everything by yourself.
So, the approach you are using will only work in the Enterprise and Ultimate versions.
For other versions, you will need to manually detach all events, remove settings and the data and maybe do something else, because, there is no way to create a new Gantt instance.