button().add()
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
button().add( index, config, draw )
Create a new button, adding it to the selected button instance and inserting immediately into the document.
Parameters:
Name | Type | Optional | |
---|---|---|---|
1 | index | No | |
Insert index for the button. This option can be one of:
| |||
2 | config | No | |
Button configuration. Please refer to | |||
3 | draw | Yes - default:true | |
Since 2.1.0: Indicate if Buttons should immediately draw the new button ( |
Returns:
DataTables.Api
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'
});