enable/disable buttons not working on search event
enable/disable buttons not working on search event
![abanet](https://secure.gravatar.com/avatar/f849bc22182160682c518010e9fec7cf/?default=https%3A%2F%2Fvanillicon.com%2Ff849bc22182160682c518010e9fec7cf_200.png&rating=g&size=120)
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: