+ Start a Discussion
robertcw777robertcw777 

Display Child Records in Table

I have a  custom object Parent__c and child records Child__c. I want to show fields from the child record that corresponds with its parent record. But, I want the titles for each child column to appear only at the top of the Visualforce table. Like:

 

Parent Field TItle     Child Field 1 Title        Child Field 2 Title        Child Field 3 TItle

P1.Value                             P1.C1.Value                  P1.C1.Value                 P1.C1.Value

                                             P1.C2.Value                  P1.C2.Value                 P1.C2.Value

P2.Value                             P2.C1.Value                  P2.C1.Value                 P2.C1.Value

                                             P2.C2.Value                  P2.C2.Value                 P2.C2.Value                                                     

                                             P2.C3.Value                  P2.C3.Value                 P2.C3.Value

etc.

 

Does anyone know how to do this?

 

Thanks!

Jake GmerekJake Gmerek

Hey,

 

You should be able to do that with nested pageblocktables.

 

<apex:pageblocktable value = "{!myParentList}" item = "parent">

<apex:column value = {!parent.name}"/>

<apex:column>

  <apex:pageblocktable value = "{!parent.child__r}" item = "child">

  

 

..and so on.  You may have to play with it to show it exactly how you want, but the general idea should get you there.

robertcw777robertcw777

Thanks for your help, but I must be doing something wrong. When I first implemented as you suggested, I got an error saying that "item" is an invalid field for pageblocktable. I presumed you meant "var" and changed accordingly. Then I ran into compile errors saying that pageblocktable must be contained within a pageblock section. I added that and got an error when the page loaded saying that pageblocktable must be contained within a pageblocksection. Below is code. Perhaps I'm not implementing as you suggested?

 

<apex:page controller="dbPracticeChangesController">
 <apex:pageblocksection >
  <apex:pageblocktable value="{!ChangeList}" var="parent">
    <apex:column value="{!parent.name}"/>
      <apex:pageblocksection>
      <apex:pageblocktable value="{!parent.dbPracticeChanges__r}" var="child">      
       </apex:pageblocktable>
      </apex:pageblocksection>
  </apex:pageblocktable>
 </apex:pageblocksection>
</apex:page>