+ Start a Discussion
CLitesCLites 

pageBlockTable rows reorder after rerender

Hi,

 

I am a bit stuck on a problem and I was hoping that someone might be able to help. I am creating an inline visualforce page with a page block table. the table displays different images on each row when a user clicks on the image but when the table refreshes, the rows in the table reorder themselves. the image changes correctly but I need the order of the rows to remain constant. I am really stuck as to trying to figure out why these rows are reordering themselves. any help would be greatly appriciated. the page and controller are below.

 

<apex:page standardController="Project__c" extensions="ProjectRequirementLinkController">

     <apex:form >
     	<apex:actionFunction action="{!methodOne}" name="methodOneInJavascript" rerender="selectLineItemsTable">
	        <apex:param name="firstParam" assignTo="{!testId}" value="" />
	    </apex:actionFunction>
	    			    
		<apex:pageBlock >
			<apex:pageBlockButtons >
			<div>
			<apex:commandLink action="{!CreateRequirements}" target="_top" value="Link/Unlink Requirements" styleClass="btn" oncomplete="window.top.location='/{!Project__c.id}'; return false"/>
			<apex:commandLink action="{!URLFOR($Action.Requirement__c.New)}" target="_top" value="New Requirement" styleClass="btn" type="image/png"/>
			</div>
			</apex:pageBlockButtons>
			<apex:pageBlockSection title="Requirements for Account: {!Project__c.Account__r.Name}" columns="1">
		  		<apex:pageBlockTable id="selectLineItemsTable" value="{!linkedRequirements}"  var="item" width="95%">
		    		
		    		
		    		<apex:column >
		      			<div>
					    <apex:outputPanel onclick="methodOneInJavascript('{!item.requirement.Id}')" > 
					        <apex:image id="added" value="{!URLFOR($Resource.Checkboxes, item.picture)}"/> 
					    </apex:outputPanel>
       					 </div>
		    		</apex:column>
       					
       					
		    		<apex:column >
		      			<apex:facet name="header">Requirement Name</apex:facet>
		      			<apex:outputLink value="/{!item.requirement}" target="_blank">{!item.requirement.Name}</apex:outputLink>
		    		</apex:column>
		    		
		    		<apex:column >
		      			<apex:facet name="header">Requirement Subject</apex:facet>
		      			<apex:outputText value="{!item.requirement.Subject__c}"/>
		    		</apex:column>
		    		
		    		<apex:column >
		      			<apex:facet name="header">Requirement's Project</apex:facet>
		      			<apex:outputLink value="/{!item.requirement.Project__c}" target="_blank">{!item.requirement.Project__r.Name}</apex:outputLink>
		    		</apex:column>
		    		
		  		</apex:pageBlockTable>
			</apex:pageBlockSection>			
		</apex:pageBlock>
	</apex:form>
	
</apex:page>

 

 

public with sharing class ProjectRequirementLinkController {


/*Initialization*/
    public ProjectRequirementLinkController(ApexPages.StandardController controller) {
    	
    	projId=controller.getId();
    	
        proj2 = [SELECT Id, Name, Account__r.Id, Account__r.Name
				FROM Project__c 
        		WHERE Project__c.Id =: projId limit 1];		
        
       	loadRequirements();
       	
    }
    
/*End Initialization*/

/*Properties*/
 
    private final Project__c proj2;
    public Map<Id, SelectAddDeleteSObject> linkedRequirements2 {get; set;}
    public List<SelectAddDeleteSObject> linkedRequirements {
    	get{return linkedRequirements2.values();}
    	set;}
    private Id projId {get; set;}
     
    
/*End Properties*/

/*Action Methods*/


	private SelectableSObject SSO;
	public Id testId {get; set;}
	public String state = 'Checkboxes/SF_Checkbox_Unchecked.jpg';
	
    public void methodOne() {
    	if(linkedRequirements2.get(testId).status == SelectAddDeleteSObject.State.selected)
        {
        	linkedRequirements2.get(testId).status = SelectAddDeleteSObject.State.deleted;
        	linkedRequirements2.get(testId).picture = 'Checkboxes/SF_Checkbox_Red_X.jpg';
        }
        else if(linkedRequirements2.get(testId).status == SelectAddDeleteSObject.State.deleted)
        {
        	linkedRequirements2.get(testId).status = SelectAddDeleteSObject.State.selected;
        	linkedRequirements2.get(testId).picture = 'Checkboxes/SF_Checkbox_Checked.jpg';
        }
        else if(linkedRequirements2.get(testId).status == SelectAddDeleteSObject.State.unselected)
        {
        	linkedRequirements2.get(testId).status = SelectAddDeleteSObject.State.added;
        	linkedRequirements2.get(testId).picture = 'Checkboxes/SF_Checkbox_Checked_Green.jpg';
        }
        else if(linkedRequirements2.get(testId).status == SelectAddDeleteSObject.State.added)
        {
        	linkedRequirements2.get(testId).status = SelectAddDeleteSObject.State.unselected;
        	linkedRequirements2.get(testId).picture = 'Checkboxes/SF_Checkbox_Unchecked.jpg';
        }

    }
    
    
    
    
    public PageReference CreateRequirements()
    {
    	try
    	{
	    	List<Requirement__c> toUpdate = new List<Requirement__c>();
	    	for(SelectAddDeleteSObject currentRequirement : linkedRequirements2.values()){
	    		
	    		if(currentRequirement.status == SelectAddDeleteSObject.State.added){
	    			
	    			currentRequirement.requirement.Project__c = projId;
	    			toUpdate.add(currentRequirement.requirement);
	    		}
	    		else if(currentRequirement.status == SelectAddDeleteSObject.State.deleted){	
	    			currentRequirement.requirement.Project__c = null;
	    			toUpdate.add(currentRequirement.requirement);
	    		}
	    	}
	    	update toUpdate;
    	}
    	catch (DmlException e)
    	{
    		system.debug(LoggingLevel.ERROR, e.getMessage());
    	}
    	loadRequirements();
    	return null;
    }
/*End Action Methods*/

/*Helper Methods*/
	public void loadRequirements() {
		linkedRequirements2 = new Map<Id, SelectAddDeleteSObject>();
		linkedRequirements = new List<SelectAddDeleteSObject>();
		
		for(Requirement__c current_req : [SELECT Id, Name, Subject__c, Project__c, Project__r.Name
	        	  							FROM Requirement__c
	        	  							WHERE (Requirement__c.Account__r.Id =: proj2.Account__r.Id)
	        	  							])
		{
		    SelectAddDeleteSObject SAD_req = new SelectAddDeleteSObject(current_req);
		    
		    if(current_req.Project__c == projId){
		    	SAD_req.status = SelectAddDeleteSObject.State.selected;
		    	SAD_req.picture = 'Checkboxes/SF_Checkbox_Checked.jpg';
		    } 
		    linkedRequirements2.put(current_req.Id, SAD_req);
		}  
	}
/*End Helper Methods*/   






}

 

 

Thanks,

 

Chris