I'm trying to disable buttons in my custom display controller. I can disable "Add" button in my DataTables with this piece of code:
var can_create = $('#user_groups_table').attr('data-create');
if (can_create.includes('false')) {
table.button('.buttons-create').disable();
} else {
table.button('.buttons-create').enable();
}
However I can't make this one to work for my custom display controller:
$('#user_groups_table').on('click', 'td.details-control', function() {
var tr = this.parentNode;
var can_destroy = $('#user_groups_table').attr('data-destroy');
if (table.row(tr).child.isShown()) {
editor.close();
} else {
if (can_destroy.includes('false')) {
table.button('.DTE_Form_Buttons delete-button').disable();
} else {
table.button('.DTE_Form_Buttons delete-button').enable();
}
editor.edit(
tr,
'Edit row', [{
className: "update-button",
label: "Update",
"fn": function() {
editor.submit();
}
}, {
className: "delete-button",
label: "Delete",
"fn": function() {
// Show delete dialog with confirmation
editor
.title('Delete record')
.buttons('Confirm delete')
.message('Are you sure you want to remove this record?')
.remove(tr, '', null, false);
}
}]
);
}
});
In my console log I can see can_destroy
value is passed correctly, however later on nothing happens with my "Delete" button. I assume, it's not connecting somehow together since this is form generated inside table when row is opened.
How do I fix this, please?
So far I've been trying to implement something from this buttons() API, however no luck.