How to disable the Remove button upon row elect when a value is > 0 ?
How to disable the Remove button upon row elect when a value is > 0 ?
I defined the 2 buttons :
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
]
on selecting a row , when a value is > 0 I need to avoid removing this row by disabling the Remove button ...
var nb_users;
table
.on( 'select', function ( e, dt, type, indexes ) {
var rowData = table.rows( indexes ).data().toArray();
nb_users = rowData[0].nb_users;
if (nb_users > 0) {
$('#groups_wrapper .dt-buttons a.buttons-remove:first').addClass('disabled');
}
.on( 'deselect', function ( e, dt, type, indexes ) {
if (nb_users > 0) {
$('#groups_wrapper .dt-buttons a.buttons-remove:first').removeClass('disabled');
}
} );
but this doesn't work... any help or clue will be appreciated ...
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Instead of adding and removing the CSS class, call the datatables built in function on the button itself to disable and enable it:
https://datatables.net/reference/api/button().disable()
Or you could enable using false:
https://datatables.net/reference/api/button().enable()
Thanks .. it's working
on select