{hero}

buttons.buttons.init

Since: Buttons 3.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 function provides the ability to button plug-in authors to run custom code when a button is initialised. This can be useful for attaching event handlers to the host DataTable that will update the button. For example, the buttons provided by the Select extension for DataTables make use of this to create buttons types which are only active when there is one or more items selected in the DataTable.

Type

function init( dt, node, config )

Description:

The function given here is called when the button is built (or re-built) and can therefore be used to attach custom events to the host DataTable (or any other object) which are specific to this button.

Parameters:
Returns:

No return value is required or expected. No action is taken upon any value that is returned.

Default

  • Value:

Default function depends upon the button type. Please refer to the button type documentation

Example

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

new DataTable('#myTable', {
	layout: {
		topEnd: {
			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();
					}
				}
			]
		}
	}
});