I have a data table with max-row-selection="1" attribute to show radio button. Once user select radio button for a row and save that selected record checkbox field will become true in the salesforce.

Now I want to show the selected radio button for the row for which it was checked earlier when the data table loads. How can I do this?

I have tried to set selectedRows variable with the selected record Id when data loads during connectedcallback but it doesn't get selected.

 <lightning-datatable max-row-selection="1" key-field="Id" data={dummyData} columns={cols} selected-rows={selectedRows}> </lightning-datatable>
handleGetInfo() {
    getInfo({recordId: this.recordId})
    .then((result) => {
        this.dummyData = result;
        this.error = undefined;
        for(let d of this.dummyData ){
                this.selectedRows = d.Id;
                console.log('handleGetInfo '+ d.Id);
    .catch((error) => {
        this.error = error;

1 Answer 1

            this.selectedRows = [];

I forgot that selectedRows stores a list of Ids. So doing the above change set the default radio during loading time.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .