{hero}

key

Since: KeyTable 2.0.0

A key event has been detected on the table and is not handled by KeyTable.
Please note - this property requires the KeyTable extension for DataTables.

Description

This event is triggered by KeyTable when a key is pressed by the end user and the following conditions are met:

  • KeyTable is enabled (keys.enable() and keys.disable())
  • A cell in the DataTable has focus
  • KeyTable does not handle the key event itself (for example an arrow key will trigger a focus change and this event will not be triggered).

This event is triggered from a keydown event that KeyTable itself listens for. The original event is passed in as the fourth parameter to the event handlers allowing the preventDefault and stopPropagation methods of the event being triggered, which can be useful if you wish to trigger some action such as editing the content of the cell.

Type

function function( e, datatable, key, cell, originalEvent )

Parameters:

Example

Trigger inline editing with Editor when the enter key is pressed. Note that the keys.editor option can be used to provide a similar interface.:

var table = new DataTable('#myTable', {
	keys: true
});

table.on('key', function (e, datatable, key, cell, originalEvent) {
	if (key === 13) {
		// return
		// timeout needed to let inline initialise
		setTimeout(function () {
			editor
				.one('close', function () {
					table.keys.enable();
				})
				.inline(cell.node());
		}, 100);

		table.keys.disable();
	}
});

Related

The following options are directly related and may also be useful in your application development.