{hero}

buttons.buttons

Since: Buttons 3.0.0

List of buttons to be created.
Please note - this property requires the Buttons extension for DataTables.

Description

The buttons.buttons array defines the buttons that will appear in the document to the end user. Each element in the array can be one of:

  • string - The name of a built-in button type or plug-in button type. This is the equivalent of using { extend: ... }.
  • object - A custom button or a customisation of an existing button type. The extend property (see buttons.buttons.extend) can be defined to tell Buttons which button type to base the button on, and any of the configuration options you wish to customise. Alternatively, if the extend option is not given, use the text and action options to define a button. Buttons has only a few built in configuration options for each button, but the various button types may provide additional options. Please refer to the documentation for each button type for information on the further options they provide. The built-in options are:
  • function - A function that will be executed upon creation of the buttons. The function is passed only a single argument, the DataTables API instance for the host DataTable, and the result value should match the above options, or an array of the above options.

Type

array

Description:

This array defines a list of the buttons that are to be shown in the button collection. There are a variety of options that each element in the array can take including strings, objects and functions. Please see the documentation above for full details. The array can contain multiple of each type.

Examples

buttons as an array using basic types:

new DataTable('#myTable', {
	layout: {
		topEnd: {
			buttons: ['copy', 'csv', 'print']
		}
	}
});

Two buttons, one with customisations:

new DataTable('#myTable', {
	layout: {
		topEnd: {
			buttons: {
				buttons: ['copy', { extend: 'excel', text: 'Save as Excel' }]
			}
		}
	}
});

A fully custom button:

new DataTable('#myTable', {
	layout: {
		topEnd: {
			buttons: {
				buttons: [
					'copy',
					{
						text: 'My button',
						action: function (dt) {
							console.log('My custom button!');
						}
					}
				]
			}
		}
	}
});

Instance initialisation: Using the buttons array:

new DataTable.Buttons(table, {
	buttons: ['copy', { extend: 'excel', text: 'Save as Excel' }]
});