javascript - Allow selecting of row once for each datatable shown -


i using datatables.js https://www.datatables.net/ , running in problem want user select 1 row reach table shown.

i've tried several things can't work, script checks datatables instead of 1 selecting in. understand because in code fetching tables using var table = $('table').datatable();

but have no idea how specify checks if selected class set on 1 of rows in datatables.

var table = $('table').datatable();  $('table tbody').on( 'click', 'tr', function () {     if ( $(this).hasclass('selected') ) {         $(this).removeclass('selected');     }     else {         table.$('tr.selected').removeclass('selected');         $(this).addclass('selected');     } } ); 

in on() event row's table instead of using table defined outside of function.

code

$('table tbody').on( 'click', 'tr', function () {     var table = $(this).closest("table");     if ( $(this).hasclass('selected') ) {         $(this).removeclass('selected');     }     else {         table.$('tr.selected').removeclass('selected');         $(this).addclass('selected');     } } ); 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -