button().text()

Since: Buttons 1.0.0

Get / set the text for the selected button. Please note - this property requires the Buttons extension for DataTables.

Description

This method provides the ability to dynamically get and set the display text of one or more buttons. This can be useful if an interaction (such as row selection) changes the behaviour of a button, to let the end user know what that change in behaviour is.

Types

function button().text()

Description:

Get the display text for the selected button.

Note that if the button's text option is specified as a function, this method will execute that function and return the result, so a string is always returned.

Returns:

The current display string from the button.

function button().text( set )

Description:

Set the display text for the selected button

Parameters:
Returns:

DataTables API instance with the selected button in the result set, available for chaining further operations on the buttons.

Examples

Get the text for button index 1:

var table = $('#myTable').DataTable();
var buttonText = table.button( 1 ).text();

Use an action to display a button activation counter:

var table = $('#myTable').DataTable();
var button = table.button( 0 );
var counter = 0;

button
	.text( 'Click counter: 0' )
	.action( function () {
		counter++;
		this.text( 'Click counter: '+counter );
	} );

Use a function to display the text:

var table = $('#myTable').DataTable();

table.button( 0 ).text( function ( dt, button, config ) {
	return dt.i18n( 'buttons.input', 'Input' );
} );