off()
Remove an event listener.
Please note - this property requires the Editor extension for DataTables.
Description
Editor triggers a number of custom events which can be useful for taking action when those events occur. For example, it can be useful to know when a form is opened through the open event.
Editor provides three methods for working with Editor events, matching the core jQuery event methods:
This off() method is used to remove a listener that has already been attached to a Editor. Simply pass in the event you wish to remove the listener, and optionally the specific function if you want to remove only a single event listener.
Type
off( name [, fn ] )
Remove an event listener from the Editor instance
Parameters:
| Name | Type | Optional | |
|---|---|---|---|
| 1 | name | No | |
Event name to remove. Multiple events can be removed for using a space separator or namespacing, just as with | |||
| 2 | fn | Yes | |
Specific callback function to remove if you want to unbind a single event listener. If not given, all events which match the event name / namespace given in the first parameter will be removed. | |||
Returns:
DataTable.Editor: Editor instance
Examples
Add an event to alert when the form is shown and then remove:
editor.on('open', function () {
alert('Form displayed!');
editor.off('open');
// could also have used `editor.one()` to obtain this effect
});Client-side validation using preSubmit:
editor.on('preSubmit', function () {
if (this.get('first_name') === '') {
this.error('first_name', 'This field is required');
return false;
}
return true;
});