Topic: Deselect all on MDBDatatable
Joel priority asked 3 days ago
Hi guys,
How can I deselect all selected checkboxes on a MDBDatatable when using selectable rows?
Thanks.
Best,
Joel
Kamila Pieńkowska staff answered 3 days ago
By clicking at the top checkbox - in select/deselect all rows. If you won't to do it with JS you can trigger click on this checkbox once or twice depending on its state.
Joel priority commented 2 days ago
Hi Kamila,
Thanks for writing back.
I was looking for a piece of javascript code which could help. I've tried this, but it doesn't work:
var checkboxes = document.querySelectorAll('.datatable tbody tr input.datatable-row-checkbox:checked'); checkboxes.forEach(function(checkbox) { checkbox.checked = false; checkbox.dispatchEvent(new Event('change')); checkbox.click(); });
Nothing happens.
I'm making a asyncTable.update and I want to deselect everything after I've made a bulk function based on the selected items in the datatable.
Any ideas?
Also, it seems like the update event is never fired:
dataTable.addEventListener('update.mdb.datatable', (e) => { //console.log(e.selectedRows, e.selectedIndexes, e.allSelected); console.log(e.rows); })
Joel priority commented 2 days ago
Ok, doing this solved the problem, but I don't think it's a perfect solution:
asyncTable.dispose(); dataTable.innerHTML = '';
Kamila Pieńkowska staff commented 2 days ago
Do you need any further assistance?
Joel priority commented 2 days ago
All good, take care.
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Priority
- Premium support: Yes
- Technology: MDB Standard
- MDB Version: MDB5 8.1.0
- Device: MacBook
- Browser: Chrome
- OS: Mac OS X
- Provided sample code: No
- Provided link: No