{hero}

create

Since: Editor 1.5.0

A button that will create a new row using Editor.
Please note - this property requires the Editor extension for DataTables.

Description

The create button type is made available by Editor and provides an easy to use interface to call the create() method through a pre-defined button. All of the options available for the create() method's form options are available through the button options (namely formButtons, formMessage and formTitle).

This button requires that the editor option must be set, which tells the button which Editor instance to operate on when activated. In this way multiple Editor instances could be attached to a single DataTable if required.

Options

This button can have the following options set in its configuration object to customise its actions and display, in addition to those options which are available for all buttons (e.g. buttons.buttons.text):

editor

The Editor instance that this button should operate on when activated.

formButtons

The form control buttons to show in the Editor form when activated by the create button (i.e. submit, cancel, etc).

The value given here is passed directly to the buttons() method - please refer to the documentation for that method and also the button-options data type.

formMessage

The message to show in the create form. This can either be a simple string or a function that will compute a string to show when the button is activated.

The value given here is passed directly to the message() method. Please refer to the documentation for that method for full details of the options available.

formOptions

Form options to configure the behaviour of the form - see form-options for full details. The options specified here will take precedence over any configured by formOptions.main.

formTitle

The title to give the create form. This can either be a simple string or a function that will compute a string to show when the button is activated.

The value given here is passed directly to the title() method. Please refer to the documentation for that method for full details of the options available.

Examples

A single, simple create button for the Editor instance myEditor:

new DataTable('#myTable', {
	buttons: [
		{
			extend: 'create',
			editor: myEditor
		}
	]
});

Create, edit and remove buttons, all with default options:

new DataTable('#myTable', {
	buttons: [
		{ extend: 'create', editor: myEditor },
		{ extend: 'edit', editor: myEditor },
		{ extend: 'remove', editor: myEditor }
	]
});

A create button with a cancel button:

new DataTable('#myTable', {
	buttons: [
		{
			extend: 'create',
			editor: myEditor,
			formButtons: [
				{
					label: 'Cancel',
					fn: function () {
						this.close();
					}
				},
				'Create new row'
			]
		}
	]
});

A create button with a custom message:

new DataTable('#myTable', {
	buttons: [
		{
			extend: 'create',
			editor: myEditor,
			formMessage:
				'Enter the data for the new row and click the "Save" button below to save permanently.'
		}
	]
});

Related

The following options are directly related and may also be useful in your application development.