更新时间:2023-11-20 23:14:52
在DOM上使用jQuery,您只会看到可见的行.您将需要访问表的dataTables内部版本,即其缓存".这是一个"checkall"函数,它遍历所有行,更改了.checkbox1
类的复选框的选中状态:
By using jQuery on the DOM you only reach visible rows. You will need to access dataTables internal version of the table, i.e its "cache". Here is a "checkall" function iterating over all the rows, changing the checked state for a checkbox with the class .checkbox1
:
$('#checkall').click(function(event) { //on click
var checked = this.checked;
table.column(0).nodes().to$().each(function(index) {
if (checked) {
$(this).find('.checkbox1').prop('checked', 'checked');
} else {
$(this).find('.checkbox1').removeProp('checked');
}
});
table.draw();
});
演示-> http://jsfiddle.net/05xnxzbd/
demo -> http://jsfiddle.net/05xnxzbd/
以上内容实际上可以通过几种不同的方式来完成.这是最简单的方法,在第一列中有一个我们知道的复选框.使用 to$()
让我们使用jQuery在内容上.
The above can in fact be done in several different ways. This is the most simple approach, with a checkbox we know exists on the first column. Using to$()
let us work with jQuery on the content right away.
您也可以遍历table.rows().data().each(function(..
,并定位包含不同复选框的多个列,等等.
You could iterate over table.rows().data().each(function(..
as well and target multiple columns holding different checkboxes and so on.