mode()

Since: Editor 1.4.1

Get / set the mode of operation the Editor form is currently in.
Please note - this property requires the Editor extension for DataTables.

Description

This method can be used to programmatically determine which mode of operation the Editor form is currently operating in, and as of 1.7 also the set the mode of operation.

The mode is set automatically when create(), edit(), bubble(), inline() and remove() are called. While the Editor instance is in a particular mode, it can be submitted.

This method can be particularly useful in event handlers such as open to determine which mode of operation is being used, and thus trigger certain actions (showing / hiding fields for example).

As a setter, this method can be used to change the mode of operation. For example you might start a form in edit mode, and then change it to create. This effectively will create a duplicate row. Note that certain changes are pointless - specifically:

  • create to edit
  • create to remove

These mode changes should not be used. As of v1.9 attempting to use these transforms will result in an error being thrown.

Types

mode()

Get the mode of operation the Editor form is currently in.

Returns:

string: create, edit, remove or null if no active state.

mode( mode )

Since: 1.7.0

Set the mode Editor should operate in. Note that this method will throw an error when used as a setter when Editor is not yet in create, edit or remove mode (i.e. mode() returns null).

Parameters:

Returns:

DataTable.Editor: Editor instance

Examples

Log which mode the form is opened in:

editor.on('open', function (e, type) {
	var mode = editor.mode();

	console.log('Editor form displayed for a ' + mode + ' action');
});

Duplicate a row by activating in edit mode and changing to create:

editor
	.edit(table.rows({ selected: true }).indexes(), {
		title: 'Duplicate record',
		buttons: 'Create from existing'
	})
	.mode('create');