DHTMLX Docs & Samples Explorer

Index
dhtmlxDataView

## Events Handling

### Attaching/Removing Event Handler

attachEvent method can be used to add an event handler to any of the available events. To do so, the method need to be called with the following parameters:

- evName - name of the event;
- evHandler - user-defined event handler.

            function my_handler(){ do_something(); };
            view.attachEvent("onSomeEvent",my_handler);

Several handlers can be attached to one and the same event, and all of them will be executed. The names of the events are case-insensitive.

There is a simple way of removing an event-handler:

            var id = view.attachEvent("onSomeEvent",my_handler);
            ...
            view.detachEvent(id); // unique id of the event handler

All events which name contains “before” - can be blocked, returning true from such event handler will confirm operation , returning false or not returning anything will block default event processing.

### Naming tips

- events which starts from “before” - can be blocked
- events which starts from “after” - can't be blocked, but have sibling event, whit name starts from “before”

### List of supported events

The following events are available in dhtmlxGrid:

- Drag-and-Drop Events:
  - onBeforeDrag Event - drag operation is started
  - onBeforeDragIn Events - an item is dragged to another potential target
  - onDragOut Events - an item is dragged out of potential target
  - onBeforeDrop Event - an item is dragged to another target and the mouse is released
  - onAfterDrop Event - drad-n-drop operation is finished

- Editing Events:
  - onBeforeEditStart Event - edit process is initiated
  - onAfterEditStart Event - editor is ready for data input
  - onBeforeEditStop Event - editor closing is initiated
  - onAfterEditStop Event - editor is closed
  - onEditKeyPress Event - key pressed while editor is active

- Selection Events:
  - onItemClick Event - an item is clicked
  - onItemDblClick Event - an item is doubleclicked
  - onBeforeSelect Event - selection of an item is started
  - onAfterSelect Event - selection of an item is finished
  - onSelectChange Event - selection is changed
  - onMouseMove Event - mouse moved over item
  - onMouseOut Event - mouse moved out of item

- Loading Events:
  - onXLS Event - occurs before sending data request to server
  - onXLE Event - occurs after sending data request to server

- Data manipulation
  - onBeforeAdd Event - item adding is initiated
  - onAfterAdd Event - item adding is finished
  - onBeforeDelete Event - item deleting is initiated
  - onAfterDelete Event - after deleting is finished