0
當我的數據表中存在選定的複選框行時,如何啓用/禁用我的按鈕?如何啓用/禁用Datatables複選框選定行時的按鈕
var pctoreceive = $('#pcToReceive').DataTable({
'columnDefs': [{
'targets': 0,
'searchable': false,
'orderable': false,
'className': 'dt-body-center',
'render': function (data, type, full, meta) {
return '<input type="checkbox" name="id[]" value="'
+ $('<div/>').text(data).html() + '">';
}
}],
我縮短了我的代碼。上面說我添加了一個新列checkbox
節目選擇
在沒有選擇的行這兩個按鈕必須被禁止。否則啓用
$('#rc-select-all').on('click', function() {
// Check/uncheck all checkboxes in the table
var rows = pctoreceive.rows({
'search': 'applied'
}).nodes();
$('input[type="checkbox"]', rows).prop('checked', this.checked);
});
// Handle click on checkbox to set state of "Select all" control
$('#pcToReceive tbody').on('change', 'input[type="checkbox"]', function() {
// If checkbox is not checked
if (!this.checked) {
var el = $('#rc-select-all').get(0);
// If "Select all" control is checked and has 'indeterminate' property
if (el && el.checked && ('indeterminate' in el)) {
// Set visual state of "Select all" control
// as 'indeterminate'
el.indeterminate = true;
}
}
});
爲什麼它的身體嗎?爲什麼不在特定的桌子上? – qwerzxcxyz
只是因爲我沒有把任何表放在我的例子,但在你的代碼中,你應該使用特定的表格選擇器的c :) – pumpkinzzz
我試了一下,它只適用於行..但不是在選擇/取消選擇複選框header( – qwerzxcxyz