{hero}

button().add()

Since: Buttons 1.0.0

Create a new button and add it to the document.
Please note - this property requires the Buttons extension for DataTables.

Description

This method provides the ability to dynamically add new buttons to a button instance. The inverse of this method is button().remove() which can be used to remove existing buttons dynamically.

Important: This method will effect the indexes of other buttons in the instances. If you are using index based selectors for the buttons, please ensure that you take this into account for API interactions after calling this method.

When using the buttons() selector method, the second argument (the buttons selector) is effectively ignored when processing this method. Only the button instances are used.

Type

function button().add( index, config, draw )

Description:

Create a new button, adding it to the selected button instance and inserting immediately into the document.

Parameters:
Returns:

New DataTables API instance with the result set containing the newly created button. This means it is possible to immediately using the chaining API to manipulate the button.

Example

Add a new button, into index position 0, that provides the ability to reload an Ajax sourced DataTable:

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

table.button().add(0, {
	action: function (e, dt, button, config) {
		dt.ajax.reload();
	},
	text: 'Reload table'
});