I am using datatables. Trying to use select and keytable features together. Please see this jsfiddle.
$(document).ready(function() {
$('#data-table')
.DataTable({
"select": {
"style": "os"
},
"keys": true
}).on('key-focus', function() {
$('#data-table').DataTable().row(getRowIdx()).select();
})
.on('click', 'tbody td', function() {
var rowIdx = $('#data-table').DataTable().cell(this).index().row;
$('#data-table').DataTable().row(rowIdx).select();
}).on('key', function(e, datatable, key, cell, originalEvent) {
if (key === 13) {
var data = $('#data-table').DataTable().row(getRowIdx()).data();
$("#output").html("Code: " + data[0] + ". Description: " + data[1]);
}
});
});
function getRowIdx() {
return $('#data-table').DataTable().cell({
focused: true
}).index().row;
}
It almost works perfect except when press key down it doesn't unselect the first row that I clicked. It acts like as if I have pressed the shift key.
My second problem that when I press enter it shows the first column data but I need to show the row id.
I would appreciate a lot if you could help me to solve these two problems