As already pointed out in another answer, there is a single row slection example from DataTables, but unfortunately it is not fully usable and convincing. It's evident from the code that their solution is external to the package, but also from a testing experience you can see that the native selection count is not updated (and that's not nice).
Anyway the most important part of the above said example - if we want to partially re-use it - is the ability to catch the event in a situation that is not already natively managed by the table.on( 'deselect',
feauture. Which situation is it? The Ctrl + click
by which one can select multiple items. Therefore the new solution structure will be
table.on( 'click', 'tr', function () {
// https://stackoverflow.com/a/42266749/11323942
if ( event.ctrlKey ) {
//is ctrl + click
console.log("ctrl + click intercepted but forcing single select")
// NOW WHAT TO DO?
}
} );
The best thing to do now is deliver the control back to their framework's standard events.
So
// NOW WHAT TO DO?
table.rows({ selected: true }).deselect();
The above limits the selection to a single row, but it's easy to extend to a different number of rows and of course now you can perform whatever reset action you might want in the appropriate way
table.on( 'deselect', function ( e, dt, type, indexes ) {
if ( type === 'row' ) {
var deselectedrow = indexes[0]
console.log('deselected row', deselectedrow);
// perform whatever reset action you might need
}
} );