So, Say I have the following visualforce page:

<table width="100%" border="0">
      <td valign="top">
        <apex:pageBlock mode="edit" id="results">
           <apex:pageBlockTable value="{!contacts}" var="contact">
               <apex:column >
                   <apex:facet name="header">
                   <apex:outputField value="{!contact.email}"/>
                  <apex:column >
                   <apex:facet name="header">
                           <apex:commandLink reRender="detail">{!contact.name}
                     <apex:param name="id" value="{!contact.id}"/>

and the following corresponding controller:

public List<Contact> contacts = [SELECT name, division, email FROM Contact];

Say I want to break up this table on division (i.e, when there is a new division, I would like a header to be placed in the table that reads the division name, and then the names and emails of all contacts within that division to appear under the header... similar ot this:

[                    Division 1                    ]
 Email                                           Name
    ....                                         ...
    ...                                          ...
    ...                                          ...
 [                   Division 2                    ]
  Email                                         Name
  ...                                           ...
 [                   Division 3                    ]
  Email                                        Name
 ...                                             ...


Is there a way to do this inline in the apex pageblock? Or would I have to make a unique pageblock for each division?

Does anyone have an alternate approach I could take to solve this problem?

1 Answer 1


you can probably do a group by division in your 1st query and based on the selection of the division, have a separate pageblock table which queries your contact based on the division id. But if you want everything to be shown in a single page. pull all divisions in a list. Create a map and associate list of contacts for each divisionid in that map and then link it with your table. Or probably use an apex:repeat and render stuff dynamically.

  • Thank you so much for the help! You wouldn't happen to know where I could find a simple example of this, would you?
    – gfppaste
    Jan 23, 2013 at 22:01
  • I didnt browse through.. Hope my answer helped. Will let you know if I find any example. when I get some time I will write a bit of code and post it. Meanwhile let me know if you have already completed it.
    – Sathya
    Jan 28, 2013 at 20:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .