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
robertcw777robertcw777 

Nested Pageblock Tables

I need to group and display child object fields  by parent object fields in a nested VisualForce Pageblock. For example, Parent__c is the parent of Child__c. I'd like to display a table with the name of the parent in a row, and then show fields of Child__c for each name.

 

Parent         Child

 

Name1        Field1

                      Field2

                      Field3

Name2        Field1

                      Field2

                      Field3

etc.

 

 

I know how to do the parent child query in the controller:

 

List <Parent__c> ParentChildList{get;set;}

 

Public LIst <Parent__c> getQueryList() {

  ParentChildList = [Select Name,(Select Field1__c,Field2__c From Child__c) From Parent__c];

  return ParentChildList;

}

 

I'm having trouble with the nested PageBlock tables in the VisualForce page (using apex:facet) that reference the data returned by the controller to show the nested table above. Help would be much appreciated.

 

Best Answer chosen by Admin (Salesforce Developers) 
robertcw777robertcw777

Never mind. I corrected my VF page:

 

<apex:page controller="dbPracticeChangesController">
    <apex:form >
      <apex:pageblock >
      <apex:pageblocktable value="{!ChangeList}" var="cs">
               <apex:column headervalue="Competency">
                  <apex:outputtext value="{!cs.Name}"/>
               </apex:column>
               <apex:column headervalue="Rollup Data">
                  <apex:facet name="Facet Name">
                   </apex:facet>
                      <apex:pageblocktable value="{!cs.dbPracticeChanges__r}" var="db">
                         <apex:column headervalue="Name">
                            <apex:outputtext value="{!db.Name}"/>
                         </apex:column>
                         <apex:column headervalue="Late Start">
                            <apex:outputtext value="{!db.Late__c}"/>
                         </apex:column>
                      </apex:pageblocktable>                           
               </apex:column>             
         </apex:pageblocktable>
       </apex:pageblock>
      </apex:form>
</apex:page>

All Answers

SurekaSureka

public class testing { public List<Account> acc{get;set;} public testing(ApexPages.StandardController controller) { acc = new List<Account>(); acc = [Select Id,Name,(Select Id,name From contacts) From Account limit 10]; } } <apex:page standardController="Account" extensions="testing"> <apex:form> <apex:pageBlock> <apex:pageBlockTable value="{!acc}" var="a" border="1"> <apex:column value="{!a.name}"/> <apex:column> <apex:pageBlockTable value="{!a.contacts}" var="con" border="1"> <apex:column value="{!con.Name}"/> </apex:pageBlockTable> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>

Please try the above code.

 

Thanks

Sureka

robertcw777robertcw777

Thanks. I got the references right in the VF page. However, I'm not seeing the child records in the table. I should point out that they have lookup relationships to the parent object, so does this work for lookups? For testing I have 5 Competency__c records, and one of them has 3 dpPracticeChanges__c records linked via lookup.

 

Controller:

 

public with sharing class dbPracticeChangesController {

    public class dbPracticeChangesException extends Exception {}

    public List <Competency__c> CompChanges{get;set;}

            public List<Competency__c> getChangeList()

       {CompChanges = [Select Name,(Select Maturity__r.Name,LateStart__c,Late__c,ScheduleTracking__c,ExpenseTracking__c,CapitalTracking__c

                        From dbPracticeChanges__r) From Competency__c];

                return CompChanges;

       }  /* end getdbPrcChanges */ 

   }   /* end class */

 

 

 

VF:

<apex:page controller="dbPracticeChangesController">
    <apex:form >
      <apex:pageblock >
      <apex:pageblocktable value="{!ChangeList}" var="cs">
               <apex:column headervalue="Competency">
                  <apex:outputtext value="{!cs.Name}"/>
               </apex:column>
               <apex:column headervalue="Rollup Data">
                  <apex:facet name="Facet Name">
                    <apex:pageblock >
                      <apex:pageblocktable value="{!cs.dbPracticeChanges__r}" var="db">
                         <apex:column headervalue="Late Start">
                            <apex:outputtext value="{!db.LateStart__c}"/>
                         </apex:column>
                         <apex:column headervalue="Late Start">
                            <apex:outputtext value="{!db.Late__c}"/>
                         </apex:column>
                      </apex:pageblocktable>
                    </apex:pageblock>                              
                  </apex:facet>
               </apex:column>             
         </apex:pageblocktable>
       </apex:pageblock>
      </apex:form>
</apex:page>

robertcw777robertcw777

Never mind. I corrected my VF page:

 

<apex:page controller="dbPracticeChangesController">
    <apex:form >
      <apex:pageblock >
      <apex:pageblocktable value="{!ChangeList}" var="cs">
               <apex:column headervalue="Competency">
                  <apex:outputtext value="{!cs.Name}"/>
               </apex:column>
               <apex:column headervalue="Rollup Data">
                  <apex:facet name="Facet Name">
                   </apex:facet>
                      <apex:pageblocktable value="{!cs.dbPracticeChanges__r}" var="db">
                         <apex:column headervalue="Name">
                            <apex:outputtext value="{!db.Name}"/>
                         </apex:column>
                         <apex:column headervalue="Late Start">
                            <apex:outputtext value="{!db.Late__c}"/>
                         </apex:column>
                      </apex:pageblocktable>                           
               </apex:column>             
         </apex:pageblocktable>
       </apex:pageblock>
      </apex:form>
</apex:page>

This was selected as the best answer