How can I enable/disable my button when there is a selected checkbox row in my datatable?
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() + '">';
}
}],
I've shorten my code. Above shows that I added a new column for checkbox
select
Those two button must be disabled when there is no selected row. Otherwise enable
$('#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;
}
}
});
Aucun commentaire:
Enregistrer un commentaire