initEdit

Since: Editor 1.1

Form initialised for the edit action event.
Please note - this property requires the Editor extension for DataTables.

Description

Edit method activated event, fired when the edit API method has been called, just prior to the form being shown. Useful for manipulating the form specifically for the edit state.

As of Editor 1.8 the init* events can return a Promise which is used to delay the execution of any further Editor code until the Promise has been resolved. This is useful if you need to make an Ajax call to the server for any additional information, validation, locking or any other async action.

Event naming / backwards compatibility note

Prior to Editor 1.3, events were prefixed with the string on and this event was called onInitEdit. That event name can still be used, and will function exactly the same way as the event documented here. The new name is used for simplicity and coherence with the event naming conventions in DataTables.

Type

function( e, node, data, items, type )

Parameters:

Returns:

Promise:
Optionally a Promise can be returned (jQuery or native). Editor will halt its code execution until the promise is resolved. If nothing is returned, Editor will immediately continue with its code execution.

Examples

Get the row information for each row to be edited - multi-row editing:

editor.on('initEdit', function (e, node, data, items, type) {
	table.rows(items).every(function () {
		var node = this.node();
		var data = this.data();

		// ...
	});
});

Ajax call to lock this row:

editor.on('initEdit', function (e, node, data, items, type) {
	return new Promise(function (resolve, reject) {
		$.ajax({
			url: '/api/lockRow',
			data: {
				row: editor.ids()
			},
			success: function (json) {
				resolve(); // Editor continues after this
			}
		});
	});
});