attachEvent

attaches the handler to an inner event of dhtmlxGantt

string attachEvent(GanttEventName name,function handler, [object settings] );
nameGanttEventNamethe event's name, case-insensitive
handlerfunctionthe handler function
settingsobjectoptional, an object with settings for the event handler
stringthe id of the attached event handler

Example

gantt.attachEvent("onTaskClick", function(id, e) {
    alert("You've just clicked an item with id="+id);
});

Related samples

Details

You can attach several handlers to the same event and all of them will be executed. If some of handlers will return false - the related operation will be blocked. Event handlers are processed in the same order that they were attached.

Properties of settings object

The settings object can contain two properties:

1. id - (string) the id of the event handler

For example, you can easily detach a handler from the specified event:

gantt.attachEvent("onTaskClick", function(){
    console.log("task click");
}, {id: "my-click"}); ... //after a while:
gantt.detachEvent("my-click");

2. once - (boolean) defines whether the event will be executed only once

Set the property to true if you want to capture the first triggering of the event, as in:

gantt.attachEvent("onTaskClick", function(){
    console.log("capture next task click");
    return true;
}, {once: true});

3. thisObject - (object) specifies the this object for the listener

gantt.attachEvent("onTaskClick", function(){
    // ...
    return true;
}, {thisObject: this});
See also
Back to top