buttons()

Since: Editor 1.0

Define the control buttons to be shown in the form.
Please note - this property requires the Editor extension for DataTables.

Description

Editor can display buttons in each of its editing modes (edit(), bubble() and inline()) which, typically, provides the end user with a method of saving the form, or optionally closing it. However, the buttons shown are exceptionally configurable and can be configured to perform almost any action as they will run a defined function when activated.

In its simplest form, a button definition is simple a string, which is used as the label for the button and the action is automatically set to submit the form (as this is the most common action for a button in an Editor form!). More complex buttons with custom behaviour, class names, etc can be defined using as described by the button-options documentation.

Whether buttons are shown in the form or not is controlled by the buttons option in the form-options configuration object used to show the form.

Note that calling this method will replace any buttons which are currently shown in the form.

Type

buttons( btns )

Set-up the buttons that will be shown in form to control the form.

Parameters:

Returns:

DataTable.Editor: Editor instance

Examples

Create a button using a string as a label:

editor
	.title('Create new row')
	.buttons('Save')
	.create();

Create a button using an object to define the button. This results in exactly the same behaviour as the above example, but is explicit in its behaviour.:

editor
	.title('Create new row')
	.buttons({
		text: 'Save',
		action: function () {
			this.submit();
		}
	})
	.create();

Show Save and Cancel buttons:

editor
	.title('Create new row')
	.buttons([
		'Save',
		{
			text: 'Cancel',
			action: function () {
				this.close();
			}
		}
	])
	.create();

Use show() and hide() to have simple and complete displays for the form fields:

editor
	.title('Create new row')
	.buttons([
		'Save',
		{
			text: 'Simple',
			action: function () {
				this.hide(['position', 'salary', 'additional_comments']);
			}
		},
		{
			text: 'Simple',
			action: function () {
				// Show all field
				this.show();
			}
		}
	])
	.create();

Use a function to count the number of rows operating on:

editor.buttons([
	{
		text: function (editor, dt) {
			return 'Delete ' + dt.rows({ selected: true }).count() + ' rows';
		},
		action: function () {
			this.submit();
		}
	}
]);

Bootstrap save button with a class:

new DataTable('#myTable', {
	buttons: [
		{
			extend: 'create',
			editor: myEditor,
			formButtons: {
				text: 'Save',
				action: function () {
					this.submit();
				},
				className: 'btn btn-default'
			}
		}
	]
});