{hero}

buttons.buttons.available

Since: Buttons 3.0.0

Ensure that any requirements have been satisfied before initialising a button.
Please note - this property requires the Buttons extension for DataTables.

Description

A number of buttons types, particularly the file export buttons, can depend upon certain APIs being available in the web-browser and external third-party libraries having been loaded. For example the pdfHtml5 button type depends upon the FileReader API and also the pdfMake library.

This method provides button developers with the ability to ensure that any dependencies their buttons might have are satisfied before the button is shown to the end user. If the function returns false, the button is simply not shown to the end user.

Type

function available( dt, config )

Description:

This function can be used to determine if the end user's web-browser has the required functions and libraries available for the button to function correctly. If the function returns false as these requirements have not been satisfied, the button simply will not be shown to the end user.

Parameters:
Returns:

A boolean value should be returned from the function - true to indicate that the buttons requirements are available, false to indicate that they are not.

Default

  • Value:

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

Example

Ensure that the FileReader API is available:

new DataTable('#myTable', {
	layout: {
		topEnd: {
			buttons: [
				{
					text: 'FileReader available',
					available: function (dt, config) {
						return window.FileReader !== undefined;
					}
				}
			]
		}
	}
});