Deselect all on MDBDatatable


Topic: Deselect all on MDBDatatable

Joel pro premium priority asked 2 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 2 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 pro premium priority commented 20 hours 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 pro premium priority commented 19 hours 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 19 hours ago

Do you need any further assistance?


Joel pro premium priority commented 19 hours ago

All good, take care.


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Pro
  • 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