{hero}

button().enable()

Since: Buttons 1.0.0

Enable / disable the selected button.
Please note - this property requires the Buttons extension for DataTables.

Description

It can often be useful to enable and disable a button based on some external logic. A common example is an editing button that is disabled when no rows are selected in a table.

When a button is disabled its visual appearance is updated to show its deactivated status (this is done by adding the class disabled to the button element). Additionally, when a disabled button is clicked on (or otherwise activated by the keyboard or button().trigger()) the button's action is not executed.

This method can be used to dynamically change the enabled state for the selected button.

Type

function button().enable( [ state ] )

Description:

Set the enabled state for the selected button.

Parameters:
Returns:

DataTables API instance with the selected button in the result set, available for chaining further operations on the button.

Examples

Enable button index 0:

var table = new DataTable('#myTable');

table.button(0).enable();

Set enabled state on a logic condition:

var table = new DataTable('#myTable');

table
	.button('edit:name')
	.enable(table.rows({ selected: true }).indexes().length === 0 ? false : true);