2

我使用 jQuery 数据表插件创建了一个表,该插件允许选择多行。我想知道如何使用按钮一次性取消选择所有行。这是我的代码:http: //jsfiddle.net/v6VTB/5/

$(document).ready(function() {    
$('#example5').dataTable( {
        "bPaginate": true,
        "bLengthChange": false,
        "bFilter": true,
        "bSort": true,
        "bInfo": true,
        "bAutoWidth": false
    } );
    /* Add/remove class to a row when clicked on */
    $('#example5 tr').click( function() {
        $(this).toggleClass('row_selected');
    } );
 } );
 $('#example5').css('min-height','300');  
​
4

3 回答 3

1

只需删除类。

$('.btn_r').click(function() {
    $('.row_selected').removeClass('row_selected')
})

http://jsfiddle.net/EfFA2/

于 2012-11-11T19:32:30.263 回答
0

I know I'm a bit late to the party but just incase anyone comes across this, DataTables has a plugin called TableTools which has built in buttons for selecting, de-selecting entire rows. As well as for printing and other functionality.

Quick example taken from the datatables website:

  $(document).ready(function() {   
$('#example').DataTable( {        
    dom: 'T<"clear">lfrtip',        
    tableTools: {            
        "sRowSelect": "multi",            
        "aButtons": [ "select_all", "select_none" ]       
    }    
} );

} );

Here's the link: https://datatables.net/release-datatables/extensions/TableTools/examples/select_multi.html

于 2014-08-14T15:48:17.430 回答
0

在这个小提琴中尝试这样的事情

 $('.btn_r').click( function() {
     $('#example5 tr').each(function(){
          if ( $(this).hasClass('row_selected') )
            $(this).removeClass('row_selected');

     })
});
于 2012-11-12T04:54:32.437 回答