enable/disable buttons not working on search event
enable/disable buttons not working on search event
Hi,
I have a Datatable with some buttons: the edit and remove buttons for the editor and one custom button. I need to enable/disable this buttons when the user select/deselect a row.
This is working perfectly: (my custom button has a className called 'gestion'.)
tablaAsignaturaOtra.on('select deselect', function () {
var selectedRows = tablaAsignaturaOtra.rows({selected: true}).count();
tablaAsignaturaOtra.button(['.edit', '.delete', '.gestion']).enable(selectedRows === 1);
});
But then I realized that I need to do the same if the user use the search box and there is not any row selected in the result of the search so I added the search event:
tablaAsignaturaOtra.on('select deselect search.dt', function () {
var selectedRows = tablaAsignaturaOtra.rows({selected: true, search: 'applied'}).count();
tablaAsignaturaOtra.button(['.edit', '.delete', '.gestion']).enable(selectedRows === 1);
});
The problem I got is that this is working perfectly for the custom button, but for the edit and delete buttons the function is called but this two buttons remains enabled.
Am I doing something wrong? Thanks in Advance!
Answers
I just found the right answer on the forum!
https://datatables.net/forums/discussion/40015/how-can-i-disable-edit-button-by-using-table-event#Comment_104118
The key is what Allan says: