3

I am using apex:repeat value to display the names, and a vf table to display the limit and use. My issue is that I do not want the name to repeat 5 times, I only want to say the name once, and then let the table show the limit and use data.

Please see example of data below:

enter image description here

Is there a way to limit the number of times apex:repeat repeats? Or is there a better way to have David displayed once.

My goal is to have the data displayed as shown below:

enter image description here

Currently the data is displaying like this:

enter image description here

VF:

<apex:page standardController="Account">
<apex:pageBlock title="Spend">
<apex:repeat value="{!account.Spend__r}" var="Spend1">
    <b>Super Bank Name: {!Spend1.Name}    </b>
</apex:repeat>
    <apex:pageBlockTable value="{!Account.Spend_r}" var="Spend">
        <apex:column value="{!Spend.Limit__c}"/>
        <apex:column value="{!Spend.Use__c}"/>
    </apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

Thanks for your help gentlemen (and ladies)!

1
  • 1
    You can use an apex:variable to count the number of iterations, and conditionally render based on that....however, I think it might be better to put "David" outside of the iteration altogether. Could you share your wrapper and markup? Commented Dec 16, 2015 at 17:11

1 Answer 1

6

It will depend on how your data is returned.

Instead of returning a List<YOURTYPE>

Return a Map<String,List<YOURTYPE>>

With the name as the key.

Then in the VF page do something like this:

<apex:repeat value="{!myMap}" var="k">
   ...Output name here....
   <apex:repeat value="{!myMap[k]}" var="v">
      ...output values here.
   </apex:repeat>
</apex:repeat>

then it just becomes a matter of layout

2
  • Thanks for your response. The data is a child object so I do not have a controller. I just have a vf page on the parent object page layout. Commented Dec 16, 2015 at 17:15
  • 2
    Then create a controller....
    – Eric
    Commented Dec 16, 2015 at 17:22

You must log in to answer this question.

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