{hero}

button().action()

Since: Buttons 1.0.0

Get / set the action function for the selected button.
Please note - this property requires the Buttons extension for DataTables.

Description

Like its plural counterpart (buttons().action()) this method provides the ability to get or set the action function for a selected button - in this case limited to a single button only, and thus generally likely to be more useful as each button will typically provide a unique operation.

The action function (which can be set on initialisation by buttons.buttons.action) defines what the button will do when activated.

Please note that when setting an action, the new function will replace any action that the button already has assigned to it. This is an important consideration as many button types define their own action that would no longer be executed if replaced.

Types

function button().action()

Description:

Get the action function for the selected button.

Returns:

Current action function.

function button().action( set )

Description:

Set the action function 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.

Example

Set a simple action function for button index 0:

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

table.button(0).action(function (e, dt, button, config) {
	console.log('Button ' + this.text() + ' activated');
	this.disable();
});