How can we validate the entered draft values were correct or not before saving of inline datatable editing. For eg: I have built one inline editing datatable in lightning component on contacts object.Now when i edit the email field, and entered some invalid input it should throw an error like invalid email format.How can we achieve this using draft values inline editing.


The draft values saved in Inline edit are visible in the draftValues, on click of the save button you can validate the draft values and populate the errors attribute and that will automatically display the message to the user.

            columns="{! v.columns }"
            data="{! v.data }"
            errors="{! v.errors }"
            draftValues="{! v.draftValues }"
            onsave="{! c.handleSaveEdition }"

JS Save method:

handleSaveEdition  : function(component , event ,helper){

    let editedValues = cmp.get(`v.draftValues`);
    //Run your validate logic on edited values

    //if error display error on appropriate row

    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'


enter image description here

Src: Lightning Datatable - Errors Attribute

Src: https://developer.salesforce.com/docs/component-library/bundle/lightning:datatable/example#lightningcomponentdemo:exampleDatatableInlineEdit

| improve this answer | |
  • I am unable to access the saved draft values.I tried the following way. var passvalues = component.get("v.saveDraftValues"); here i am getting the values which are saved in draft values.after stringifying the below result i am getting [{"field__c":"someid","Id":"someid"}].From here i am unable to access field__c value.how to access this value. – anusha Dec 21 '18 at 6:34

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.