buttons

Since: Buttons 1.0.0

Buttons configuration object. Please note - this property requires the Buttons extension for DataTables.

Description

This option provides the ability to have a Buttons instance created automatically when a new DataTable is created. The button collection can then be inserted into the DataTables controlled DOM by using the B option in the dom parameter, or through the buttons().container() API method.

Types

array

Description:

The majority of button configurations are not concerned with the DOM configuration and other options that Buttons presents, but rather just with what buttons are presented and how they are individually constructed. As such, to provide a short-cut this option can be provided as an array. This array will be mapped automatically to the buttons.buttons option.

For example the following two configurations are functionally identical:

// Using `buttons` as an array
$('#myTable').DataTable( {
    buttons: [ 'copy', 'csv', 'excel' ]
} );
// Using `buttons.buttons`
$('#myTable').DataTable( {
    buttons: {
        buttons: [ 'copy', 'csv', 'excel' ]
    }
} );

boolean

Description:

As a boolean true value, this option will trigger the creation of a Buttons instance with the default values (as defined by $.fn.dataTable.Buttons.defaults).

object

Description:

As an object this option provides the ability to configure a single instance of the DataTables Buttons extension that will be created when the DataTable is initialised. For the full range of parameters that are available to be used in this object, please refer to the remainder of the Buttons initialisation reference.

Examples

Creation of Buttons using defaults and insertion by dom:

$('#example').DataTable( {
	dom: 'B<"clear">lfrtip',
	buttons: true
} );

Creation of Buttons with array configuration of buttons and insertion by dom:

$('#example').DataTable( {
	dom: 'B<"clear">lfrtip',
	buttons: [ 'copy', 'csv', 'excel' ]
} );

Creation of Buttons with object configuration and insertion by dom:

$('#example').DataTable( {
	dom: 'B<"clear">lfrtip',
	buttons: {
		name: 'primary',
		buttons: [ 'copy', 'csv', 'excel' ]
	}
} );

Creation of Buttons using defaults are API insertion to the DOM:

var table = $('#example').DataTable( {
	buttons: true
} );

table
	.buttons()
	.container()
	.appendTo( '#controlPanel' );