Required library edition:
Required library file: dhtmlxgrid.js
adds any user-defined handler to available events
Attaching anonymous event handler:
<script> grid.attachEvent("onRowSelect",function(rowId,cellIndex){ alert("Row with id="+rowId+" was selected"); }); </script>
Attaching pre-defined event handler:
<script> grid.attachEvent("onEditCell",doOnEditCell); ... function doOnEditCell(stage,rowId,cellIndex,newValue,oldValue){ if ((stage==2)&&(newValue!=oldValue)){ alert("Cell with id="+rowId+" and index="+cellIndex+" was edited"); return true; } return true; } </script>
Several handlers can be attached to one and the same event, and all of them will be executed.
<script> grid.attachEvent("onCheck",doOnCheck1); grid.attachEvent("onCheck",doOnCheck2); ... function doOnCheck1(rowId,cellIndex,state){ if (state){ alert("Checkbox in the row with id="+rowId+" was checked"); } } function doOnCheck2(rowId,cellIndex,state){ if (state){ alert("Checkbox in column with index="+cellIndex+" was checked"); } } </script>
If it is necessary, the custom code can be detached from an event:
var id1=grid.attachEvent("onRowSelect",myHandler); var id2=grid.attachEvent("onRowSelect",myHandler2); grid.detachEvent(id2); // detach myHandler2 from onRowSelect event
Some of the events can be blocked. So based on the return value, the grid will react differently:
grid.attachEvent("onEditCell",function(){ return false; // will block any edit operation })
Note: the names of the events are case-insensitive.
See also: detachEvent