key
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()
andkeys.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:
Name Type Optional 1 e
No jQuery event object
2 datatable
No DataTable API instance for the table in question
3 key
No The key code for the pressed key
4 cell
No A DataTables API instance that contains the cell that has focus (
cell()
)5 originalEvent
No The original key event that triggered this event
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.