function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sanchi9Sanchi9 

Default Checkbox in Lightning datatable

Hi, 
I am working on Lightning datatable. Is there any way to default select the checkbox in lightning datatable? 

User-added image
Danish HodaDanish Hoda
hi Priya,
Please refer the link (https://developer.salesforce.com/docs/component-library/bundle/lightning-datatable/documentation) and go to 'Selecting Rows Programmatically' section
Maharajan CMaharajan C
Hi Priya,

Yes you can perselect the rows by using the wrapper class or set the selectedRows (set the record Id's array) in component load JS (aura : doInit , Lwc : Connectcallback).

Refer the below sample codes surely it will help you.

For Aura : 

https://gist.github.com/sumugapadman/b31488774df70e50c9f8bf64d3c9ac33

https://salesforce.stackexchange.com/questions/268067/stuck-trying-to-preselect-rows-in-data-table

For LWC:

https://www.salesforcepoint.com/2020/07/preselected-checkbox-data-table-Lwc.html


Thanks.
Maharajan.C
Maharajan CMaharajan C
https://www.youtube.com/watch?v=ZmqFu3ezVfk
mukesh guptamukesh gupta
Hi Priya,

Default option is not available but you can set auto select when your component compleate load from controller .

below is sample code 

https://initaura.com/lightning-component-show-check-boxes-for-a-records-list-and-display-selected-record/

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh