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
Bharath VikkurthiBharath Vikkurthi 

InLine Edit not working

Hi All,
Good day!!
I created one lightning table and added Inline edit for one column .When I was trying to edit column and update the new value its not saving the record .
.Please help me out.
Here is my code 
public class BillingHoursTimesheet
 {
                @AuraEnabled
    public static List<wrapper> getBillingRecord(string invoiceid )  
   {
  
       string projectid ; 
       date start;
       date endda;
       
         
       List<Invoice__c> res =[select Start_Date__c,End_Date__c,Project__c from Invoice__c where Id=:invoiceid]; 
       if(res.size()>0){
          projectid =res[0].Project__c;
               start =res[0].Start_Date__c;
           endda =res[0].End_Date__c;
       }
       
       List<wrapper> wr =new List<wrapper>(); 
        map<String, Decimal> projMap = new map<String, Decimal>(); 
       for(Project_Team_Member__c ptm: [select Id, Employeee__r.Name , Charged_Rate__c  from Project_Team_Member__c where Project__c=:projectid  ]){
        projMap.put(ptm.Employeee__r.Name, ptm.Charged_Rate__c);       
           system.debug('Value of Rate:'+ ptm);   
       }      
       for(AggregateResult tes: [select Timesheet__r.Employeee__r.Name em , SUM(No_of_hours__c) tot from Timesheet_Detail__c where Project__c=:projectid AND  Date__c>=:start AND Date__c<=:endda group by Timesheet__r.Employeee__r.Name ])
       {
   
         
           wrapper t = new wrapper();
           t.empname =String.valueof(tes.get('em'));
           t.hour =(Decimal) tes.get('tot');
           t.chargedhour =(Decimal) tes.get('tot'); 
           t.rate=projMap.get(t.empname); 
          wr.add(t);
       } 
       
       return wr; 
      
    }
     public class wrapper{
         @AuraEnabled
        public string empname;
          @AuraEnabled 
         public decimal hour;
         @AuraEnabled 
         public decimal chargedhour;
         @AuraEnabled
         public Decimal rate;
     } 
     @AuraEnabled
     public static boolean saveAccount(List<Project_Team_Member__c> lstAccount) {  
       try { 
          
            update lstAccount;  
            return true;  
              
        } catch(Exception e) {  
          
            return false;  
              
        }  
            
        
    } 
}
 
({
                doInit : function(component, event, helper) {
                                helper.getBillingRecord(component); 
                },
    
    
    inlineEditName : function(component,event,helper){   
       
        component.set("v.nameEditMode", true); 
        
        setTimeout(function(){ 
            component.find("inputId").focus();
        }, 100);
    },
    
    Save: function(component, event, helper) {
      
        if (helper.requiredValidation(component, event)){
             
               var action = component.get("c.saveAccount");
                  action.setParams({
                    'lstAccount': component.get("v.billLst")
                  });
            action.setCallback(this, function(response) {
                var state = response.getState();
                if (state === "SUCCESS") {
                    var storeResponse = response.getReturnValue();
                    
                    component.set("v.billLst", storeResponse); 
                
                    component.set("v.showSaveCancelBtn",false);
                    alert('Updated...');
                }
            });
            $A.enqueueAction(action);
        } 
    },
    
    cancel : function(component,event,helper){
      
        $A.get('e.force:refreshView').fire(); 
    } ,
    
     closeNameBox : function (component, event, helper) {
        
        component.set("v.nameEditMode", false); 
     
        if(event.getSource().get("v.value").trim() == ''){
            component.set("v.showErrorClass",true);
        }else{
            component.set("v.showErrorClass",false);
        }
    }, 
    
    onNameChange : function(component,event,helper){ 
       
        if(event.getSource().get("v.value").trim() != ''){  
            component.set("v.showSaveCancelBtn",true);
        }
    }
    
  
})
 
<aura:component controller="BillingHoursTimesheet" implements="force:appHostable,force:hasRecordId,forceCommunity:availableForAllPageTypes,flexipage:availableForAllPageTypes" access="global">
 <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> 
    <!-- calling doInit method in Component Controller -->
    
    <aura:attribute name="showSaveCancelBtn" type="boolean" default="false" description="flag for rendered save and cancel buttons in aura:if "/>
    <aura:attribute name="showErrorClass" type="boolean" default="false"/> 
    <aura:attribute name="nameEditMode" type="boolean" default="false" />
    <aura:attribute name="ratingEditMode" type="boolean" default="false" />
    <aura:attribute name="billLst" type="List"/> <!-- create Array type object variable-->
    <aura:attribute name="sNo" type="string" />
    <article class="slds-card">
      <div class="slds-card__header slds-grid">
        <header class="slds-media slds-media_center slds-has-flexi-truncate">
          <div class="slds-media__figure">
            <span class="slds-icon_container slds-icon-standard-account" title="description of icon when needed">
                <lightning:icon iconName="standard:customers" size="large" alternativeText="List account"/>
            </span>
          </div>
          <div class="slds-media__body"> 
            <h1 style="color:#9ACD32;"> 
              <a href="javascript:void(0);" class="slds-card__header-link slds-truncate" title="Logged Hours">
                  <span class="slds-text-heading_small">LOGGED HOURS</span>
              </a>
            </h1>
          </div>
        </header>
       </div>
      <div class="slds-card__body"> 
        <table class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_col-bordered">
          <thead> 
            <tr class="slds-line-height_reset"> 
                <th scope="col">
                <div class="slds-truncate" title="S.No" >S.No</div>  
              </th>
              <th scope="col">
                  
                <div class="slds-truncate" title="Employee Name">Employee Name</div>

              </th>
              
                <th scope="col">
                <div class="slds-truncate" title="Total Hours">Total Hours</div>
              </th>
                <th scope="col">
                <div class="slds-truncate" title="Charged Hour">Charged Hour</div> 
              </th>
                <th scope="col">
                <div class="slds-truncate" title="Rate">Rate</div>
              </th>
                <th scope="col">
                <div class="slds-truncate" title="Amount">Amount</div>
              </th>
            </tr>
          </thead>
          <tbody>
              <aura:iteration items="{!v.billLst}" var="acc" indexVar="sNo">
                  
                  <!-- iteration account record.-->
                  <tr class="slds-hint-parent">
                      <td><div class="slds-truncate">{!sNo + 1}</div></td> 
                      <th scope="row">
                          <div class="slds-truncate" title="Name">{!acc.empname}</div>   
                      </th>
                     
                      <th>
                          <div class="slds-truncate" title="Hours" >{!acc.hour}</div> 
                      </th>
                     
                          <td ondblclick="{!c.inlineEditName}" class="{! v.showErrorClass == true ? 'slds-cell-edit slds-has-error' : 'slds-cell-edit'}">
            <span class="slds-grid slds-grid_align-spread">
                <!-- show input and output section based on boolean flag --> 
                <aura:if isTrue="{!v.nameEditMode == false}">
                    <span class="slds-truncate" title="Rate">{!acc.chargedhour}</span> 
                    <button onclick="{!c.inlineEditName}" class="slds-button slds-button_icon slds-cell-edit__button slds-m-left_x-small" tabindex="0" title="Edit Name">
                      <lightning:icon iconName="utility:edit" size="xx-small" alternativeText="edit"/>
                    </button>
                   
                    <!-- Inline Edit Section in else case-->  
                    <aura:set attribute="else">
                        <section  tabindex="0" class="slds-popover slds-popover_edit" role="dialog" style="position: absolute; top: 0px">
                            <div class="slds-popover__body">
                                <div class="slds-form-element slds-grid slds-wrap">
                                    <div class="slds-form-element__control slds-grow">
                                        <ui:inputText class="slds-input inputFieldWidth"
                                                      labelClass="slds-form-element__label slds-form-element__label_edit slds-no-flex"
                                                      aura:id="inputId"
                                                      blur="{!c.closeNameBox}"
                                                      change="{!c.onNameChange}"
                                                      
                                                      required="false"
                                                      label="Charged Hour"
                                                      value="{!acc.chargedhour}" /> 
                                    </div>
                                </div>
                            </div>
                            <span id="form-end" tabindex="0"></span>
                        </section>  
                    </aura:set>  
                </aura:if> 
            </span>
        </td>
                      
                      
                      
                      
                      
                      
                     <!-- <th>
                          
                          <div class="slds-truncate" title="Charged Hour" >  
                              {!acc.hour}
                          </div>         
                      </th> -->
                      
                      <th  >   
                          <div class="slds-truncate" title="Rate"  > {!acc.rate} </div>        
                      </th> 
                      
                      <th> 
                         <div class="slds-truncate" title="Amount" >
                       {!acc.chargedhour*acc.rate}
                         </div> 
                         
                      </th>  
                      </tr> 
                      
                  
              </aura:iteration>
              
               <tr class="slds-hint-parent">
                      
                      <th colspan="5"  style="text-align:right">  
                          
                         <b>Grand Total:</b>
                         
                      </th>  
                  <th >  
                           
                        SUM
                         
                      </th>  
                        
                      </tr>  
             
            
  
          </tbody>
    
        </table>
          
        <lightning:buttonGroup class="slds-m-around_medium">
            <aura:if isTrue="{!v.showSaveCancelBtn}">
                <lightning:button label="Cancel" onclick="{!c.cancel}"/>
                <lightning:button label="Save" onclick="{!c.Save}" variant="success"/>
                </aura:if>
            </lightning:buttonGroup> 
             
      </div>
         
      <footer class="slds-card__footer"><a href="javascript:void(0);"><!--View All <span class="slds-assistive-text">entity type</span>--></a></footer>
    </article>
</aura:component>


 
ANUTEJANUTEJ (Salesforce Developers) 
Hi Bharath,

Can you try checking the below code I tried to see if there is any issue with inline editing but it seems like the issue could be with your code as I used a different code to check the issue and I was able to save records and the inline editing was working for me, can you try the below link:

>> https://rajvakati.com/2018/11/13/lightningdatatable-inline-editing/

I hope this helps and in case if this comes handy can you please choose this as best answer so that it can be used by others in the future.

Regards,
Anutej 
Sangeet kaseraSangeet kasera
Hi Bharath,

You can try below code i applied and make changes accordingly and below refernce code worked for me...
https://sfdcmonkey.com/2017/12/08/lightning-data-table-inline-editing/

Above link worked for editing in text field also worked for picklist field if you want to fetch picklist value from object.

you can check above code by copy pasting it in your personal org. For any issue let me know.

I hope this helps and in case if this comes handy can you please choose this as best answer.

Regards,
Sangeet