Adds event listener to a object.
||string, name of the event, could have multiple if separated by space or comma
||object, parameters of the event
The simplest way to add an event listener is to provide the name of the event and a handler function. For example if you have a
layout (for grid, toolbar, etc. it is exactly the same) defined as follows:
You can add an event listener in the following way:
Or to execute at the end of event cycle:
You could also add event listener in the following way:
The first way is simple, but the second and third way provides additional functionality. You can add any property
object and all of them will be passed to the event handlers function as
the part of the event
argument. The event
may also contain additional parameters, for example when to trigger event before or after, you can specify
function that will be called at the end of the event.
Below is the list of properties of event object:
While adding an event listener, you can provide a namespace for the event:
It provides a convenient way to remove event listeners without specifying all event and hendler functions
they were registered with:
All event names can be found on the event page of corresponding w2ui object. In order to use them with
methods, you need to drop "on" prefix and
lowerCase first letter. For example, if the object has "onResize" event, you can use it as "resize". If it was
"onColumnClick" it should be "columnClick".
You can attach event listener to all events if you do the following:
There are several events that are common for all w2ui objects (except w2popup, w2field, w2utility, w2tooltip). They are:
When an event is triggered, the event handler function will receive one
argument - event
, which is an object with useful data related to the event.
Events can be cancelled, see w2utils.events
page for more information.