I want to have pre-selected checkbox for inline editing in Lightning:dataTable tag. So if I am using hard-coded value for ID (i.e. static value) to set value for selectedRows attribute (regarding Lightning:dataTable attribute), but same does not work If I take ID value from Apex Controller. I think this is some JSON Parsing error.

This is working:

var selectedRowsIds = ["003K000001Kul79IAB"];
component.set("v.selectedRows", selectedRowsIds);

But this is not working:

var newContID = component.get("v.wrapperDataRec.conID");
component.set("v.selectedRows", newContID);


var action = component.get("c.getOpptyData");
action.setParams({"OpptyId" : component.get("v.recordId")});
action.setCallback(this, function(response){
    var state = response.getState();

        //Pre-selected checkbox for one Conatct Record

        var selectedRowsIds = ["003K000001Kul79IAB"];
        component.set("v.selectedRows", newContID);
        //   }

Where I am doing wrong in JS?


I don't see where your newContID is being set, but presumably, you didn't make it an Array. Try:

component.set("v.selectedRows", [newContID]);

This will make a new Array with a single element in it, just like the hard-coded ID example.

  • Don’t forget to accept the answer – glls Jul 20 '18 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.