+ Start a Discussion
Surinder Singh 51Surinder Singh 51 

Lightning datatable error

Component: 

 <lightning:datatable style="width: 50%" data="{! v.ContactList }"
                             aura:id="accountDataTable"
                             columns="{! v.mycolumns }"

                             onrowselection="{!c.handleSelectedRow}"
                             keyField="Id"  onsave ="{!c.onSave}" hideCheckboxColumn="false" onrowaction="{!c.viewRecord }"
<lightning:button variant="Brand" label="Delete Selected Contacts" title="Success" onclick="{! c.handleSelectedRowdelete }"/> 

JS Controller :

handleSelectedRow: function(component, event, helper){
        var abc = event.getParam('selectedRows'); 
        
        var setRows =[];
        for(var i = 0;i<abc.length;i++ ) {
            alert('abc[i].id'+abc[i]);
            setRows.push(abc[i].id);
        } 
        
        component.set("v.selectedRows",setRows);
    },
    handleSelectedRowdelete: function(component, event, helper){
         var conList=component.get("v.selectedRows");
        alert(conList);
        var conIds =[];
        for(var i = 0;i<conList.length;i++ ) {
            
            conIds.push(conList[i].id);

        }
        alert("****Id****",conIds);
        
        var action = component.get("c.DeleteContactlist");
        action.setParams({
            'listcon' : conIds
        });
        action.setCallback(this,function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                //if update is successful
                component.set("v.showdelete",'True');
                component.set("v.ContactList",'');
                location.reload();
            }
        });
        $A.enqueueAction(action);


I want on click of Delete Selected Contacts , all selected contact should deleted. I have use onselected attribute of datatable and on selestion, I am updating selectedRows. On button click I am using SelectedRows and trying to get the id but getting error. 



Error:   Action failed: c:getContactComp$controller$handleSelectedRowdelete [Cannot read property 'id' of undefined]
Best Answer chosen by Surinder Singh 51
Surinder Singh 51Surinder Singh 51
Thanks @tushar Sharma. This was the issue. It worked now.

All Answers

{tushar-sharma}{tushar-sharma}
As javaScript is Case Sensitive so you should use Id instead of id.

If this answer helps you, please mark it as accepted.

Regards,
Tushar Sharma
https://newstechnologystuff.com/
Surinder Singh 51Surinder Singh 51
Thanks @tushar Sharma. This was the issue. It worked now.
This was selected as the best answer
Surinder Singh 51Surinder Singh 51
I have one other issue , posting other post. can you please see if any thing is missing.
rakim kenrakim ken
oulala its fine