如何激活选中所有复选框,同时使用JQuery数据表上的字母表搜索功能。
我有一个数据表,我需要字母表搜索和选择所有复选框。但是我的select all在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");
}
});发布于 2018-09-28 23:08:12
像这样试着它应该能工作
使用此库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']]
});https://stackoverflow.com/questions/52560920
复制相似问题