{hero}

buttons.buttons.init

Since: Buttons 1.0.0

Initialisation function that can be used to add events specific to this button.
Please note - this property requires the Buttons extension for DataTables.

Description

This property is an alias of the feature property buttons.buttons.init and can be used to configure the feature from the top level DataTables configuration object, rather than in the layout option (see example below). This lets you use the feature as a string rather than an object, but it does restrict the configuration if you were using multiple instances of the feature. Please refer to the documentation for buttons.buttons.init for full details and options that apply to this option.

If you are using DataTables 1.x, which does not have the layout option, use this property name, but referring to the documentation for buttons.buttons.init for full details.

Example

Enable / disable based on there being selected rows (from the Select extension):

new DataTable('#myTable', {
	layout: {
		topStart: 'buttons'
	},
	buttons: [
		{
			text: 'Enabled only with selected item',
			init: function (dt, node, config) {
				var that = this;

				dt.on('select.dt.DT deselect.dt.DT', function () {
					that.enable(dt.rows({ selected: true }).any());
				});

				this.disable();
			}
		}
	]
});