buttons().collectionRebuild()
Rebuild a buttons collection.
Please note - this property requires the Buttons extension for DataTables.
Description
This function is used to change, or update the contents of collection buttons. This makes it possible to effortlessly add buttons to collections without having to redeclare the collection buttons.
Type
function buttons().collectionRebuild( buttons )
- Description:
Rebuild the contents of the buttons collection based on the array that is passed in.
- Parameters:
Name Type Optional 1 buttons
Yes An array that is full of objects, strings or functions that are used to create buttons. Please refer to
buttons.buttons
for full details of the configuration options available here.- Returns:
DataTables API instance with the selected buttons in the result set, available for chaining further operations on the buttons.
Examples
Add excel button to collection buttons:
var table = new DataTable('#myTable', {
buttons: [
{
extend: 'collection',
text: 'print',
buttons: ['csv', 'pdf']
},
{
extend: 'collection',
text: 'print',
buttons: ['csv', 'pdf']
}
]
});
table.buttons([0, 1]).collectionRebuild(['csv', 'pdf', 'excel']);
Remove csv button from collections:
var table = new DataTable('#myTable', {
buttons: [
{
extend: 'collection',
text: 'print',
buttons: ['csv', 'pdf']
},
{
extend: 'collection',
text: 'print',
buttons: ['csv', 'pdf']
}
]
});
table.buttons([0, 1]).collectionRebuild(['pdf']);
Empty collections:
var table = new DataTable('#myTable', {
buttons: [
{
extend: 'collection',
text: 'print',
buttons: ['csv', 'pdf']
},
{
extend: 'collection',
text: 'print',
buttons: ['csv', 'pdf']
}
]
});
table.button([0, 1]).collectionRebuild([]);