Documentation

attachEvent

attaches the handler to an inner event of the component (allows behaviour customizations)

id attachEvent(string type,function functor, [id id] );

Parameters

typestringthe event name, case-insensitive
functorfunctionthe function object or name
ididthe event id

Returns

idthe id of the attached event handler

See also

Example

dtable.attachEvent("onAfterLoad",function(){
    this.select(2);
})

- ...mixed... function the callback receives different set of parameters for different events. Check the documentation of the related events. - result boolean returning false will block the default behaviour (works not for all events, check the details below).
Details

How the handler is provided

You can use the method with an inline function or provide just the global function reference. In the second case, be sure that the function is visible from the calling point.

function doTask(){ ... };
dtable.attachEvent("onBeforeLoad", doTask); //uses the reference
dtable.attachEvent("onBeforeLoad", "doTask"); //will work as well, but not recommended

The handler id

The last parameter allows you to define the id of the attached handler. If it was not specified, some unique value will be assigned as the id. The only purpose of such id - detaching the handler from an event (in most cases you don't need to care about the handler's id).

Callback

Check the related documentation to get the full list of parameters. The amount and meaning will vary for different events.

The value which is returned by an event can change behavior of component. Returning true or nothing will be considered as the positive signal, while returning false will be considered as a signal to stop the current activity.

dtable.attachEvent("onBeforeSelect", function(id){
    if (id == 123)
        return false; //blocks selection of a specific element
});

Multiple handlers

You can attach multiple handlers to one and the same event and they won't overwrite each other. If some of handlers will return false - the related operation will be blocked.

Event handlers are processed in the same order as they were attached.

Back to top