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
Kavita KaleKavita Kale 

Display error in lightning:datatable

Hi,

I am using a lightning:datatable to display data-
 <lightning:datatable columns="{!v.columns}"
                             data="{!v.data}"
                             keyField="id"
                             errors="{!v.errors}"
                             show-row-number-column= "true"  
                             onrowselection="{! c.getSelectedRow}"/>

Using a button to validate the data before it gets updated in salesforce.
Sending a response back to helper in Map<Id, String> -

response- {"a1Fn00000007AEpEAM":"This contact is already assigned as an Emergency Contact, choose a different contact and save","a1Fn00000007AEoEAM":"This contact is already assigned as an Emergency Contact, choose a different contact and save","a1Fn00000007AF9EAM":"This contact is already assigned as an Emergency Contact, choose a different contact and save","a1Fn00000007AF8EAM":"This contact is already assigned as an Emergency Contact, choose a different contact and save","a1Fn00000007AFTEA2":"This contact is already assigned as an Emergency Contact, choose a different contact and save","a1Fn00000007AFSEA2":"This contact is already assigned as an Emergency Contact, choose a different contact and save"}

As per lightning documentation, lightning:datatable attribute error shoudl be set in following format-
cmp.set('v.errors',
{ rows:
{ b:
{ title: 'We found 2 errors.',
messages: [ 'Enter a valid amount.', 'Verify the email address and try again.' ],
fieldNames: ['amount', 'contact'] }
},
table:
{ title: 'Your entry cannot be saved. Fix the errors and try again.', messages: [ 'Row 2 amount must be number', 'Row 2 email is invalid' ]
}
});

I am not sure how to iterate over a map to set error attribute in this format. Any help will be appreciated.
MagulanDuraipandianMagulanDuraipandian
Use selectedRows attribute.
Since you are validating before calling apex, use Salesforce Toast event in Lightning Component - http://www.infallibletechie.com/2018/07/salesforce-toast-event-in-lightning.html.