{hero}

buttons().collectionRebuild()

Since: Buttons 2.0.0

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:
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([]);