Topic: Datatable
Petr Urban pro premium priority asked 11 months ago
Dear MDB, I'm using you MDBDatatable with the following setup:
<MDBDatatable id="myTable_checks"
data-cy="myTable_checks"
:dataset="checks"
:search="searchFilter"
:searchColumns="searchableKeys"
selectable multi
@selected-rows="rowSelected">
</MDBDatatable>
Is there any possibility to force the selected row programatically? I would like to have some rows preselected once the page is loaded. I tried to add the 'selected' field with value 'true' to dataset, but it doesn't have any effect to view.
Thanks in advance.
BR, Petr
Bartosz Cylwik staff answered 11 months ago
Hello! Unfortunately we do not provide a method/key that would allow to change the checkboxes to true on init.
With some custom JS we can try to make it work though. Dispatching a change
event on checkboxes will make them become selected and everything should work fine.
Checkout this snippet with example on how I've set some of the checkboxes to true after init - the selected
event is triggering aswell.
https://mdbootstrap.com/snippets/vue/b-cylwik/5856985#js-tab-view
Best Regards!
Petr Urban pro premium priority commented 11 months ago
Hello Bartosz, thanks for snippet it is working well in my project. Just one note the first checkbox with id = 0 is the 'SelectAll' so there is necessary to skip this one.
Thanks for your help!!!! Petr
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- User: Pro
- Premium support: Yes
- Technology: MDB Vue
- MDB Version: MDB5 4.1.1
- Device: macBook
- Browser: chrome
- OS: mac os
- Provided sample code: No
- Provided link: No