{hero}

buttons.buttons.key

Since: Buttons 1.0.0

Define an activation key for a button.
Please note - this property requires the Buttons extension for DataTables.

Description

Buttons has the built in ability to activate buttons through keyboard key presses and key combinations. This is to aid accessibility and provide complete keyboard navigation of your table. For example, with using Editor, records can be added, edited and deleted without touching the mouse!

Key presses are only processed when the document has no element that is actively focused. This means that typing into an input element will not accidentally trigger a button's action!

Please note that for Adobe Flash based buttons, key activation simply will not work! This is a security feature implemented by Adobe - such buttons must be clicked on to activate them.

Types

string

Description:

As a string this option will set the key to be listened for. It should be a single character (since multiple characters can't be pressed at the same time!). The character is case insensitive.

object

Description:

The object form of this option provides additional control over which key(s) will activate a particular button, providing the option to define filtering by meta keys such as shift, alt and ctrl.

The object properties available are:

  • key - The character to listen for. The character is case insensitive.
  • shiftKey - When set to true activation will only occur if the shift key is also being held.
  • altKey - When set to true activation will only occur if the alt key is also being held.
  • ctrlKey - When set to true activation will only occur if the ctrl key is also being held.
  • metaKey - When set to true activation will only occur if the cmd key (Mac) or Windows key (Windows) is also being held.

Multiple options can be defined if you wish to restrict activation to a specific, complex, key combination.

Default

  • Value: undefined

Examples

DataTables initialisation: Set a single key for a button:

$('#myTable').DataTable( {
	buttons: [
		{ extend: 'print', key: 'p' }
	]
} );

DataTables initialisation: Require alt key:

$('#myTable').DataTable( {
	buttons: [
		{
			extend: 'print',
			key: {
				key: 'p',
				altKey: true
			}
		}
	]
} );

Instance initialisation: Require alt key:

new $.fn.dataTable.Buttons( table, {
	buttons: [
		{
			extend: 'print',
			key: {
				key: 'p',
				altKey: true
			}
		}
	]
} );