You need to sign in to do that
Don't have an account?
Kavita 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.
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.
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.