Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

So, Say I have the following visualforce page:

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

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
 ...                                             ...

etc...

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?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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 '13 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 '13 at 20:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.