1

As per the salesforce documentation we can display error for lightning datatable by setting the "error" attribute.

I followed the same but it is not turning the cell border red and displaying a tooltip on the number column while performing inline edit on multiple rows.

JS:

saveHandleAction(event) {
        console.log('inside saveHandlerAction==');
        var draftValues = event.detail.draftValues;
        var availableRecords = this.taskObj.data;
        var totalErrors = 0;
        var errors = {};
        var rowsError = {};      
                draftValues.forEach(function(draftRecord){
            var rowErrorMessages = [];
            var rowErrorFieldNames = [];
            var totalPercent = 0;
            
            availableRecords.forEach(function(originalRecord){
                if(draftRecord.Id == originalRecord.Id) {
              
             if(totalPercent != 100) { //condition added to forcefully throw error for testing purpose
                    rowErrorMessages.push('Overall percentage must be equals to 100');
                    rowErrorFieldNames.push('Name');
                }
                
                if (rowErrorMessages.length > 0) {
                    totalErrors += rowErrorMessages.length;

                    rowsError[originalRecord.Id] = {
                        messages: rowErrorMessages,
                        fieldNames: rowErrorFieldNames,
                        title: originalRecord.Name + ' has ' + rowErrorMessages.length + ' error(s)'
                    }; 
                }   
                }   
            });
                                             
        });
         if (totalErrors > 0) {
         var tableMessages = [];// new List<String>();
                
        var rowErrorValues = Object.values(rowsError);
        rowErrorValues.forEach(function (rowError) {
            tableMessages.push(rowError.title);
        });
        
        errors = {
            
            rows: rowsError,
            table: {
                title : 'Some records have errors', // the title of the popover
                messages : tableMessages // A list of messages to be displayed as the popover content
            }
        };
        console.log('Error Details>>'+JSON.stringify(errors));
        
    }
        
    }

HTML:

<lightning-datatable key-field="Id" 
                data={taskObj.data} 
                columns={columns} 
                onsave={saveHandleAction}
                draft-values={fldsItemValues}
                onrowaction={handleRowActions} 
                show-row-number-column='true'
                errors= {errors}
                >
               </lightning-datatable>

**Console Log:**


 Error Details>>{"rows":{"a0W0r000003ecdUEAQ":{"messages":["Overall percentage must be equals to 100"],"fieldNames":["Name"],"title":"Test Record"}},"table":{"title":"Some records have errors","messages":["Test Record has 1 error(s)"]}}

In the error log I get the respective id but for some reason the error message is not appearing on row nor the tooltip is showing.

0

You must log in to answer this question.

Browse other questions tagged .