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
PipDennoPipDenno 

How can I Rerender a pageblock section when clicking on a pageblocktable row.

I have a page which queries to data from a customer table. This is then displayed in a pageblocktable in a pageblock with many row.

 

I want to have (if possible) a pageblock that will display the details of a record based on a record being selected 'onclick' but I can't seem to figure out how to rerender the pageblock based on clicking an item in the pageblocktable. I have tried using the actionSupport but this doesn't see to work inside the pageblocktable?

 

Any help is appreciated.

Best Answer chosen by Admin (Salesforce Developers) 
SiddharthSiddharth

I have done a similar stuff where based on what record is selected from the table you can show the details in the second page block. 

 

VF Page code - Main Table

 

<apex:pageBlockSection columns="1" title="Select Transaction" id="allocatesection" >
   <apex:outputPanel layout="block" style="overflow:auto;height:{!transactionFrameSize}px" id="transregion">
   <apex:pageBlockSectionItem >
      <apex:pageblocktable value="{!transactions}" var="tran" rendered="{!(transactionListSize>0)}" id="transregion2"> 
         <apex:column headerValue="Select" width="10px">
              <apex:inputCheckbox id="select" value="{!tran.selected}" disabled="{!if((isTransactionSelected==true),true,false)}">
                   <apex:actionSupport event="onclick" action="{!currentTransaction}" rerender="seltransregion" />
              </apex:inputCheckBox>
         </apex:column>

      </apex:pageblocktable>
   </apex:pageBlockSectionItem>
   </apex:outputPanel>
</apex:pageBlockSection>

 

 

VF Page Code - Secondary Table

 

<apex:pageBlockSection columns="1" title="Your Selected Transaction" id="seltransregion" collapsible="false" >
   <apex:pageBlockSectionItem >
   <apex:pageblocktable value="{!selectedTransaction}" var="tran" rendered="{!(transactionListSize>0)}" id="selTransTable">
         <apex:column headerValue="{!$ObjectType.Transaction__c.fields.Name.label}" width="25px">
             <apex:outputLabel value="{!tran.Name}" />
        </apex:column>
        <apex:column headerValue="{!$ObjectType.Transaction__c.fields.Transaction_Type__c.label}">
               <apex:outputLabel value="{!tran.Transaction_Type__c}" />
        </apex:column>

     </apex:pageblocktable>
   </apex:pageBlockSectionItem>
</apex:pageBlockSection>

 

 

 

Apex Code

public PageReference currentTransaction()
{

  Boolean sflag=false;
  for(TransWrapper wrapper : transactions)
  {
     if(wrapper.selected == true)
     {
         //Place Your Code here
     }
  }
  return null;
}

 

 

 

/* Wrapper class for Transaction for dynamic display */
public class TransWrapper
{
 public Transaction__c sobj{get; set;}
 public Boolean selected {get; set;}

 public TransWrapper(Transaction__c a)
  {  
    sobj = a;
    selected = false;
  }
}

 

Above code should help you

All Answers

Suman KunduSuman Kundu

Though I can't understand the exact scenario, but I would suggest you to check if there is any condition ( rendered attribute ) in the pageblock section (which you are rerendering) or not. If yes, I would suggest not to rerender the pageblock section directly. Put this pageblock section in an output panel and rerender this panel.

 

If this is not the case, you may post the code section for better understandability.

SiddharthSiddharth

I have done a similar stuff where based on what record is selected from the table you can show the details in the second page block. 

 

VF Page code - Main Table

 

<apex:pageBlockSection columns="1" title="Select Transaction" id="allocatesection" >
   <apex:outputPanel layout="block" style="overflow:auto;height:{!transactionFrameSize}px" id="transregion">
   <apex:pageBlockSectionItem >
      <apex:pageblocktable value="{!transactions}" var="tran" rendered="{!(transactionListSize>0)}" id="transregion2"> 
         <apex:column headerValue="Select" width="10px">
              <apex:inputCheckbox id="select" value="{!tran.selected}" disabled="{!if((isTransactionSelected==true),true,false)}">
                   <apex:actionSupport event="onclick" action="{!currentTransaction}" rerender="seltransregion" />
              </apex:inputCheckBox>
         </apex:column>

      </apex:pageblocktable>
   </apex:pageBlockSectionItem>
   </apex:outputPanel>
</apex:pageBlockSection>

 

 

VF Page Code - Secondary Table

 

<apex:pageBlockSection columns="1" title="Your Selected Transaction" id="seltransregion" collapsible="false" >
   <apex:pageBlockSectionItem >
   <apex:pageblocktable value="{!selectedTransaction}" var="tran" rendered="{!(transactionListSize>0)}" id="selTransTable">
         <apex:column headerValue="{!$ObjectType.Transaction__c.fields.Name.label}" width="25px">
             <apex:outputLabel value="{!tran.Name}" />
        </apex:column>
        <apex:column headerValue="{!$ObjectType.Transaction__c.fields.Transaction_Type__c.label}">
               <apex:outputLabel value="{!tran.Transaction_Type__c}" />
        </apex:column>

     </apex:pageblocktable>
   </apex:pageBlockSectionItem>
</apex:pageBlockSection>

 

 

 

Apex Code

public PageReference currentTransaction()
{

  Boolean sflag=false;
  for(TransWrapper wrapper : transactions)
  {
     if(wrapper.selected == true)
     {
         //Place Your Code here
     }
  }
  return null;
}

 

 

 

/* Wrapper class for Transaction for dynamic display */
public class TransWrapper
{
 public Transaction__c sobj{get; set;}
 public Boolean selected {get; set;}

 public TransWrapper(Transaction__c a)
  {  
    sobj = a;
    selected = false;
  }
}

 

Above code should help you

This was selected as the best answer
PipDennoPipDenno

Thanks.  A greate help.