I have a repeat control that populates commandbuttons(view,edit,delete) for each record of an object. On click of a command button I want to delete the respective record and render the containing output panel. The code attached actually deletes the record but it looks like it postbacks the page and the panel doesn't show any record though it actually has records. I tried without the actionfunction, just by adding rerender="leftOPanel" in commandbutton, I could not see any change in the list, but if I refresh I could see the record deletion. The rerender occurs before java script remote method for deletion completes?! I don't understand what is going wrong here. The record is getting deleted successfully in all the cases, but only this rerender is not working fine.
global with sharing class ProjectController {
public static List<Project__c> lstproj{get; set;}
public Project__c prj{get; set;}
public ProjectController(ApexPages.StandardController controller)
{
prj = new Project__c();
lstproj = [SELECT Name,Proj_Name__c,Status__c,Abstract__c
FROM Project__c ];
}
@RemoteAction
global static List<Project__c> DeleteProj(String projId) {
Project__c[] proj;
proj = [SELECT id,Name,Proj_Name__c,Status__c,Abstract__c
FROM Project__c WHERE Name = :projId];
if(proj.size() > 0 || proj[0].Id != ''){
delete proj;}
lstproj = [SELECT Name,Proj_Name__c,Status__c,Abstract__c
FROM Project__c ];
return lstproj;
}}
VF page
<apex:page sidebar="false" standardController="Project__c" extensions="ProjectController" >
<apex:form >
<apex:pageBlock mode="edit" >
<apex:outputPanel id="leftOPanel" >
<ul class="slds-has-dividers--top">
<apex:repeat value="{!lstproj}" var="p">
<li >
<h3 >{!p.Proj_Name__c}</h3>
<div>
<ul>
<li><apex:commandbutton value="View" /></li>
<li><apex:commandbutton value="Edit" /></li>
<li><apex:commandbutton value="Delete" onclick="DeleteProject('{!p.Name}');" /></li>
</ul>
</div>
</li>
</apex:repeat>
</ul>
</apex:outputPanel>
<apex:actionFunction name="rerenderleftOPanel" rerender="leftOPanel" />
</apex:pageBlock>
</apex:form>
<script>
function DeleteProject(projId)
{
Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.ProjectController.DeleteProj}',projId,function(result,event){ var r=event.message;alert(result.length);},{escape:true});
rerenderleftOPanel();
}
</script></apex:page>