数据表1.10通过jquery“检查所有”

我知道这可能看起来很原始,但我一直试图实现它一整天,也许是因为我无法完全理解如何使用API​​,我使用DataTables 1.10.0,我有一个分页的表function,每行都有一个复选框,我需要一个“检查所有按钮”,它会检查所有页面中的所有复选框,问题是它只检查当前页面中的复选框,并且不检查其他页面,这应该很容易,但我无法理解! 我找到的答案使用“fnGetNodes”,似乎已被弃用,版本1.10没有使用

编辑:这是我的标记

Number Company Tags
<input type='checkbox' name='numbers[]' value=''/>
$(document).ready(function() { $('#numbers_table').dataTable({ //"bPaginate": false, "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 0 ] } ] }); $("#checkall2").click(function() { // a button with checkall2 as its id $(':checkbox').prop('checked', true); // all checkboxes, you can narrow with a better selector }); });

试试这段代码:

 var table = $('#numbers_table').DataTable(); var cells = table .cells( ":checkbox" ) .nodes(); $( cells ).prop('checked', true); 

资源。

这应该适合你

 var table = $('#numbers_table').DataTable(); $('#checkall').click(function () { $(':checkbox', table.rows().nodes()).prop('checked', this.checked); }); 

如果不起作用尝试使用api()关键字:

 $('#YourCheckBoxId').on('click', function () { var rows = YourDatatableVariable.api().rows({ 'search': 'applied' }).nodes(); $('input[type="checkbox"]', rows).prop('checked', this.checked); }); 

它真的不是那么难,但没有看到你的标记,我只能提供一个通用的例子 –

 $('input[value="Check All"]').click(function() { // a button with Check All as its value $(':checkbox').prop('checked', true); // all checkboxes, you can narrow with a better selector });