vue.jsgantt-chartdhtmlx

How to use gantt.destructor()?


I use DHTMLX GANTT with Vue.

When a gantt is created, and i change to another page and i return, there are not all functions available.

In the dhtmlx forum they give a link to : https://docs.dhtmlx.com/gantt/desktop__multiple_gantts.html

But the method const ganttChart = Gantt.getGanttInstance();is not defined if i try to do the same in my application.

Is there a way to completely destroy a component in vue? I tried with v-if, with :key, with $forceUpdate() but no success. There remains still some gantt components in the DOM. When i refresh the page, it works.

Is there another way to destroy the component that he render from scratch?


Solution

  • The gantt.destructor function gave me some problems too in Vue.

    I solved it changing the gantt reference and detaching the events attached during the initialize in the like beforeDestroy Vue lifecycle, like this:

    <div class="gantt" :id="ganttId"></div>
    
    mounted () {
       this.ganttId = 'gantt-' + this.createUUID()
       this.initializeGannt()
    }
    
    beforeDestroy() {
        gantt.detachEvent("onTaskClick");
        gantt.detachEvent("onAfterTaskUpdate");
    }
    
    methods {
        initializeGannt () {
            ...
            gantt.attachEvent("onTaskClick", (id, e) => {
              ...
            }, {id: "onTaskClick"});
    
            gantt.attachEvent("onAfterTaskUpdate", (id, e) => {
              ...
            }, {id: "onAfterTaskUpdate"});
            ...
        }
    

    }