Adds event listener to a object.
on(type, handler)
type |
string, name of the event |
handler |
function, JavaScript function |
OR
on(eventData, handler)
eventData |
object, parameters of the event |
handler |
function, JavaScript function |
Returns
undefined.
Description
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:
You could also add event listener in the following way:
The first way is simple, but the second way provides additional functionality. You can add any property
to
eventData object and all of them will be passed to the event handlers function as
the part of the
event argument. The
eventData object
may also contain additional parameters, for example when to trigger event before or after, you can specify
onComplete function that will be called at the end of the evert.
Below is the list of properties of eventData object:
Event Names
All event names can be found on the event page of corresponding w2ui object. In order to use them with
on() and
off() methods, you need to drop "on" prefix and
lower case 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). They are:
- onRender
- onRefresh
- onResize
- onDestroy
Event Handlers
When any of the event is triggered and it has an event handler, 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.