jquery - 如何在使用 JQuery DataTable 的字母搜索时激活全选复选框?
问题描述
如何在 JQuery 数据表上使用字母搜索功能时激活全选复选框。
我有一个数据表,我需要字母搜索和全选复选框。但是在 JQuery 数据表中使用字母搜索时,我的全选不起作用。
https://jsfiddle.net/yxLrLr8o/2216/
let datatable = $('#productTable').DataTable({
"paging": false,
alphabetSearch: { column: 0},
"scrollY": "200px",
dom: 'Alfrtip',
columnDefs: [{
orderable: false,
className: 'select-checkbox',
targets: 0
}],
select: {
style: 'os',
selector: 'td:first-child'
},
order: [
[1, 'asc']
]
});
datatable.on("click", "th.select-checkbox", function() {
if ($("th.select-checkbox").hasClass("selected")) {
datatable.rows().deselect();
$("th.select-checkbox").removeClass("selected");
} else {
datatable.rows().select();
$("th.select-checkbox").addClass("selected");
}
}).on("select deselect", function() {
("Some selection or deselection going on")
if (datatable.rows({
selected: true
}).count() !== datatable.rows().count()) {
$("th.select-checkbox").removeClass("selected");
} else {
$("th.select-checkbox").addClass("selected");
}
});
解决方案
像这样尝试它应该可以工作
使用这个库https://www.gyrocode.com/projects/jquery-datatables-checkboxes/
$(document).ready(function (){
var table = $('#productTable').DataTable({
alphabetSearch: { column: 0},
"paging": false,
dom: 'Alfrtip',
'columnDefs': [
{
'targets': 0,
'checkboxes': {
'selectRow': true
}
}
],
'select': {
'style': 'multi'
},
'order': [[1, 'asc']]
});
推荐阅读
- angular - 如何防止通过角度的父组件单击禁用的按钮?
- c# - 检查文本框不为空
- angular - 拦截器不拦截 http 请求(Angular 6)
- java - 使用 ResultSet 和 HashMap 从一对多数据库关系查询中检索唯一对象列表
- objective-c - ObjectiveC Accessibility API:取消最大化窗口
- javascript - 选中/取消选中复选框时启用/禁用下拉菜单
- java - 通过键在 PriorityQueue 中查找元素
- spring-boot - Jacoco + JUnit 5.0 DynamicTest 不工作
- java - 将 .wav 文件转换为字节数组,然后在 Java 中将字节数组写入 .wav 文件?
- python - 合并后保留数据框的顺序