You need to sign in to do that
Don't have an account?
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.
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
Please try the above code.
Thanks
Sureka
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>
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>