Detaching Events

I am setting up a gantt chart and need to handle events differently based on one of three options. Initially, there is no problems. However, as soon as I select one of the other options and the chart refreshes, the events seem to still get handled, but they are stacked on top of each other, and that causes errors with my system. When I try to detach the existing events before attaching the new ones, by using the “gantt.detachAllEvents();”, I get errors and am unable to finish rendering the chart.

The error says “Uncaught TypeError: Cannot read property ‘removeEvent’ of undefined” and occurs on line 920 of the full dhtmlxgantt.js. I really need help in getting this resolved as quickly as possible. Thanks.

Which version of the gantt are you using ?

Using detachAllEvents can break the functionality of gantt in any case, as it will remove all event handlers, ones defined by custom logic, and one that was defined by the gantt itself to link different parts and functionality.

The more safe approach, will be to store the result of attachEvent command and user detachEvent against them when necessary.

var events = []; events.push( gantt.attachEvent(some, handler) ); events.push( gantt.attachEvent(some, handler) ); ... for (var i=0; i<events.length; i++) gantt.detachEvent(events[i]); events = [];

Thanks for the quick reply! This did solve my issue! I don’t know if you have access to the Docs or not, but I would recommend adding a note on the API for detachAllEvents(); so that other people know it doesn’t just detach the custom events, that it does all events and could be breaking.

Thanks again!