[英]Check all/uncheck all - checkboxes and tabular data
我目前正在使用Footables显示表格数据。 每行都有一个复选框。 有一个主复选框可以全选。 我遇到了一些困难。 该表有一个过滤器。 当我应用过滤器并尝试检查该过滤器中的所有复选框时,它将无法正常工作。 另外,由于我能够一次选中所有复选框,因此可以取消选中所有复选框吗? 例
复选框功能
$(document).on('change','input[name="check_all"]',function() {
$("input[type=checkbox]").attr('checked', true);
});
$(document).on('change','select',function() {
$('input[type=checkbox]').attr('checked', false);
});
表格过滤器
$(function () {
$('table').footable().bind({
'footable_filtering': function (e) {
var selected = $('.filter-status').find(':selected').text();
if (selected && selected.length > 0) {
e.filter += (e.filter && e.filter.length > 0) ? ' ' + selected : selected;
e.clear = !e.filter;
}
},
'footable_filtered': function() {
var count = $('table.demo tbody tr:not(.footable-filtered)').length;
$('.row-count').html(count + ' rows found');
}
});
$('.clear-filter').click(function (e) {
e.preventDefault();
$('.filter-status').val('');
$('table.demo').trigger('footable_clear_filter');
$('.row-count').html('');
});
$('.filter-status').change(function (e) {
e.preventDefault();
$('table.demo').data('footable-filter').filter( $('#filter').val() );
});
});
您仍选中所有框的原因是,您在jquery中没有正确设置过滤器。 更改为此:
$(document).on('change', 'input[name="check_all"]', function () {
$("table.demo tbody tr:not(.footable-filtered) input[type=checkbox]").prop('checked', this.checked);
alert($("input:checkbox:checked").length);
});
尝试
$(document).on('change', 'input[name="check_all"]', function () {
$(".footable tr:visible input[type=checkbox]").prop('checked', this.checked);
});
尝试使用not
选择器的方法,它将选择除.footable -filtered
类之外的.footable -filtered
$(document).on('change', 'input[name="check_all"]', function () {
$(".footable tr:not(.footable-filtered) input[type=checkbox]").prop('checked', this.checked);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.