Javascript 复选框检查问题
我的数据表中的复选框检查有问题。Javascript 复选框检查问题,javascript,jquery,datatable,Javascript,Jquery,Datatable,我的数据表中的复选框检查有问题。 未选中分页复选框。我的代码是: // Handle click on "Select all" control $('#example-select-all').on('click', function(){ // Check/uncheck all checkboxes in the table var rows = candidateTable.rows({ 'search': 'applied' }).nodes(); consol
未选中分页复选框。我的代码是:
// Handle click on "Select all" control
$('#example-select-all').on('click', function(){
// Check/uncheck all checkboxes in the table
var rows = candidateTable.rows({ 'search': 'applied' }).nodes();
console.log(rows);
$('input[type="checkbox"]', rows).prop('checked', this.checked);
});
html:
<table id="candidates-table" class="display compact nowrap" style="width:100%">
<thead>
<tr>
<th><input type="checkbox" name="select_all" value="1" id="example-select-all"></th>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Drive</th>
<th>Department</th>
<th>Experience</th>
<th>Status</th>
<th></th>
</tr>
</thead>
</table>
名字
姓氏
电子邮件
驱力
部门
经验
地位
js:
var candidateTable=$(“#候选表”).DataTable({
columnDefs:[
{宽度:“10%”,目标:-1,}
],
“国家拯救”:没错,
“响应”:正确,
“处理”:假,
“延迟渲染”:正确,
“订单”:[[3,“已禁用”],
“ajax”:{
“url”:baseUrl+“管理员/候选人”,
“dataSrc”:”
},
“fnCreatedRow”:函数(nRow、aData、iDataIndex){
$(nRow.attr('id','candidate-'+aData.id);
},
“栏目”:[
{
“呈现”:函数(数据、类型、内容、元){
返回“”;
}
},
{
“呈现”:函数(数据、类型、内容、元){
返回content.firstname;
}
},
]
});
//句柄单击“全选”控件
$(“#示例全选”)。在('click',function()上{
//获取应用搜索的所有行
var rows=candidateTable.rows({'search':'applied'}).nodes();
//选中/取消选中表中所有行的复选框
$('input[type=“checkbox”]',rows.prop('checked',$(this).is(':checked'));
});
你能添加一个提琴样本吗?你是否尝试过:`$('input[type=“checkbox”]',rows.prop('checked',$(this).is(':checked')`@谢谢你的回复。我添加给定的代码。但它的工作原理和以前一样请给我你的HTML样本。
var candidateTable = $('#candidates-table').DataTable({
columnDefs: [
{ width: '10%', targets: -1, }
],
"stateSave": true,
"responsive" : true,
"processing": false,
"deferRender": true,
"order": [[3,"disabled"]],
"ajax": {
"url": baseUrl + "admin/candidates",
"dataSrc": ""
},
'fnCreatedRow': function (nRow, aData, iDataIndex) {
$(nRow).attr('id', 'candidate-' + aData.id);
},
"columns": [
{
"render": function (data, type, content, meta) {
return '<input type="checkbox" name="id[]" value="' + content.id + '">';
}
},
{
"render": function (data, type, content, meta) {
return content.firstname;
}
},
]
});
// Handle click on "Select all" control
$('#example-select-all').on('click', function(){
// Get all rows with search applied
var rows = candidateTable.rows({ 'search': 'applied' }).nodes();
// Check/uncheck checkboxes for all rows in the table
$('input[type="checkbox"]', rows).prop('checked', $(this).is(':checked'));
});