Deleting a selected row isn't triggering deselect event
Deleting a selected row isn't triggering deselect event
Link to test case:
http://live.datatables.net/xalimeva/1/edit
Description of problem:
If you select a row and then delete it the deselect event isn't be triggered. You can see this behavior in the linked example. The console logs that event when you deselect the row by hand but not when you delete a selected row. Is it reasonable to expect that the deselect event should be triggered on delete (we have code we'd like to run when that happens)?
https://datatables.net/reference/event/deselect
There is a possible related issue as well. If you delete all of the rows from the table the delete button remains active even though there are no more rows left to delete. This appears to be related to the init option for the delete button. If you comment out the init section, rerun it and delete all of the rows the delete button becomes disabled as you'd expect. The code for the init was taken from this example:
https://datatables.net/reference/option/buttons.buttons.init
Is there a way to get the delete button to work properly (i.e. disable itself when there are no more rows) while using the init option?
Thanks.
Ben
Replies
I guess they're not being deselected, they're just being removed, so technically the code is correct. There are two things you could do - both involving the Editor callbacks.
Either deselect before the remove with:
see here for that: http://live.datatables.net/xalimeva/2/edit
or similarly, also add your logic for the deselect into that
preRemove
.Colin
Colin,
Yeah, I suppose once the selected row has been deleted it no longer exists so you can't really deselect it. Your solution works great though. Thanks!
Ben
By the way, regarding the other issue I mentioned, it turns out that if you update the event listener in the init (the one I took from the documentation example) to listen on the draw event as well as select and deselect then when you delete one or more rows the delete button updates appropriately and ends up disabled until you select another row.
Ah, sorry, I missed that other point, was too focused on the select.
Colin