Salesforce-Not able to update records after being changed in a pageblock table having inline editing

2.8k Views Asked by At

I have created a search query which returns the records in a table. I have used command in the records returned so that i can edit them and save them in the table only. But after changing the records in the table and clicking on the SAVE button, I am not able to update the the records in the table. How can I use 'rerender' to show the updated data? The page code and controller action I'm using are below:

<!-- Page -->
<apex:pageBlock id="pb1">
  <apex:outputPanel id="pan">
    <apex:pageBlockTable value="{!l1}" var="k" rendered="{!flag}" id="pb">
      <apex:column value="{!k.First_Name__c}"/>
      <apex:inlineEditSupport showOnEdit="saveButton, cancelButton" hideOnEdit="editButton" event="ondblclick" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
      <apex:column value="{!k.Last_Name__c}"/>
      <apex:inlineEditSupport event="ondblclick" showOnEdit="save"/>
      <apex:column value="{!k.E_mail__c}"/>
      <apex:inlineEditSupport event="ondblclick" showOnEdit="save"/>
      <apex:column value="{!k.Employee_ID__c}"/>
      <apex:commandButton action="{!save}" id="saveButton" value="Save" />
    </apex:pageBlockTable>
  </apex:outputPanel>

  <apex:commandButton action="{!edit}" id="editButton" value="Edit"/>
  <apex:commandButton action="{!save}" id="saveButton" value="Save"/>
  <apex:actionSupport event="onclick" rerender="pan" status="refreshstatus"/>
  <apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
  <apex:actionStatus id="refreshstatus" startstyle="color:green;" startText="Saving....">
  </apex:actionStatus>
</apex:pageBlock> 

// controller action
public pagereference save(){update l1;return null;}}
1

There are 1 best solutions below

1
On

Posting some of your code would go a long way here, but the long and the short of it is this:

<!-- put your table in a panel with an ID -->
<apex:outputPanel id="thePanel:>
  <!-- put your table here -->
</apex:outputPanel>

<!-- specify the panel's ID as the rerender target for the action -->
<apex:commandButton value="Save" action="{!TheSaveAction}" rerender="thePanel"/>

And then make sure your controller returns a Pagereference with a value of null:

public Pagereference TheSaveAction()
{
  // save
  return null;
}

If you're still struggling after doing this, put in the page code (or the relevant parts) so I can see what's going on.