jQuery数据表checkall

trr*_*rrm 5 checkbox jquery html-table

HTML

<div class="box">
<table id="Datatable">
    <thead>
       <tr>
         <th><input name="checkall" type="checkbox" class="checkall" value="ON" /></th>
         <th>field</th>
         <th>field</th>
         <th>field</th>
         <th>field</th>
         <th>field</th>
      </tr>
   </thead>
   <tbody>
      <tr>
        <th class="checkers"><input type="checkbox" name="selected[]"/></th>
        <td>value</td>                                          
        <td>value</td>  
        <td>value</td>  
        <td>value</td>  
        <td>value</td>  
      </tr>
   </tbody>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用checkall复选框选择使用此代码的所有复选框:

$('.checkall').click(function () {
        var checkall =$(this).parents('.box:eq(0)').find(':checkbox').attr('checked', this.checked);
        $.uniform.update(checkall);
    });
Run Code Online (Sandbox Code Playgroud)

当datatable显示前10,20,30 ...等行并从DOM中删除其他行以进行分页时,此jQuery代码仅选择当前页面中的行.那么无论如何我可以选择所有复选框吗?

car*_*man 7

我的解决方案也有效:

$('.checkall').click(function(e) {

          var chk = $(this).prop('checked');

          $('input', oTable.fnGetNodes()).prop('checked',chk);
        });
Run Code Online (Sandbox Code Playgroud)

如果你想检查只过滤(如果你使用dom过滤数据表),那么你可以使用它,只检查过滤

$('.checkall').click(function(e) {

          var chk = $(this).prop('checked');

          $('input', oTable.$('tr', {"filter": "applied"} )).prop('checked',chk);
        });
Run Code Online (Sandbox Code Playgroud)


trr*_*rrm 5

我找到了解决方案

$('.checkall', oTable.fnGetNodes()).click(function () {
Run Code Online (Sandbox Code Playgroud)