I would like to change the value of a cell in datatables. The idea is to switch between pre-set values when pressing spacebar on a focussed cell. But i am not sure how to implement this.
I am initializing DataTable in the following way.
var table = $('#data-table').DataTable();
var keys = new $.fn.dataTable.KeyTable( table );
Anybody has a suggestion?
Appears that the documentation of KeyTables 2.0 is not updated yet. I managed to do it in the following way:
var table = $('#data-table').DataTable();
var keys = new $.fn.dataTable.KeyTable( table );
table.on( 'key', function ( e, datatable, key, cell, originalEvent ) {
if (key == 32) { #32 for spacebar
var currentStatus = cell.data();
switch(currentStatus) {
case 'p':
cell.data('f');
$(cell.node()).removeClass('status_p').addClass('status_f');
break;
case 'f':
cell.data('h');
$(cell.node()).removeClass('status_f').addClass('status_h');
break;
case 'h':
cell.data('p');
$(cell.node()).removeClass('status_h').addClass('status_p');
break;
default:
cell.data('p');
$(cell.node()).attr('class','').addClass('status_p');
}
}
});
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments