As per below salesforce documentation we can display error for lightning datatable by setting the "error" attribute.
https://developer.salesforce.com/docs/component-library/bundle/lightning:datatable/documentation
triggerError: function (cmp, event, helper) {
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'
]
}
});
}
the above example is for showing one error. Since lightning:datatable
has multi-edit functionality, a user can try to edit multiple rows at the same time.
is there any way to display the error for all the edited rows?
I tried to do something like below, but I am getting compilation error.
component.set('v.errors', {
rows: [{
a: {
title: 'We found 2 errors.',
messages: [
'Enter a valid amount.',
'Verify the email address and try again.'
],
fieldNames: ['estDebt', 'responsibility']
}
},
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'
]
},
{
b: {
title: 'We found 2 errors.',
messages: [
'Enter a valid amount.',
'Verify the email address and try again.'
],
fieldNames: ['estDebt', 'responsibility']
}
},
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'
]
}]
});