You need to sign in to do that
Don't have an account?

apex:repeat to build table. Need to show/hide html tag.
I'm trying to show or hide a <tr> HTML tag inside an apex:repeat, but can't find a way where SFDC will save the code without error. Basically I'm building a table and want to start a new <tr> if a certain condition is met (item number mod 3 = 0, so create a new row when the table row has three cells). Attached is a simplifed example, but it shows what I'm trying to do.
Note: I can't use an apex:panelGroup because I have nested repeaters in each "column".
Thanks!
Controller:
public with sharing class TestBuildTable { public List<Integer> Ints {get;set;} public TestBuildTable() { this.Ints = new List<Integer>(); for (Integer i=0; i<20; i++) { this.Ints.add(i); } } }
VF page first try (fail):
<apex:page id="TestBuildTable" Controller="TestBuildTable"> <table> <apex:repeat value="{!Ints}" var="int"> {!IF(MOD(int,3)==0,'<tr>',' ')} <td>{!int} nested repeat here</td> {!IF(MOD(int,3)==0,'</tr>',' ')} </apex:repeat> </table> </apex:page>
VF page second try (fail):
<apex:page id="TestBuildTable" Controller="TestBuildTable"> <table> <apex:repeat value="{!Ints}" var="int"> <apex:outputPanel rendered="{!MOD(int,3)==0}" layout="none"><tr></apex:outputPanel> <td>{!int}</td> <apex:outputPanel rendered="{!MOD(int,3)==0}" layout="none"></tr></apex:outputPanel> </apex:repeat> </table> </apex:page>
The desired result is a table that looks like this:
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
It looks like you just want to wrap your list of data into 3 columns? If so, have you looked at panelGrid? It automatically flows the data into rows (see the example on the VisualForce docs page, e.g.:
I called it a panelGroup, but I meant panelGrid when I said that it wasn't an option. I'm using nested repeats, and they don't work with panelGroups.
From SFDC documentation: "Note that if an<apex:repeat>component is used within an <apex:panelGrid>component, all content generated by the<apex:repeat>component is placed in a single <apex:panelGrid>cell. The<apex:panelGrid>component differs from<apex:dataTable>because it does not process a set of data with an iteration variable."
Can you reformat your data differently in your controller so that you CAN use a panelGrid? I think the whole point of apex is that you aren't supposed to write table-based HTML directly.
If it is possible to go with API version 18 or below in your case, then this code can be saved under 18 or below api versions. you can try it.
If you put your data in a wrapper class you could do it with a combination of <apex:outputText> tags.
Keep in mind this is pseudo-code...if you haven't already solved it, let me know and I can spiff it up.
** EDIT: Forgot the escape="false" needs to be on the outputText tag.
Let me know if you need help.
-Andy
i am having a issue in writing tr and td inside the output text values for example:
<apex:outputText escape="false"
rendered="{!IF((cLife.Display_name__c == ansList.C_Life_Questions__r.Country_Life_section__r.Display_name__c),true, false)}"
value=" <tr > <td style=text-align:right> "
how to resolve it??
Thanks in advance
'm having the same issue, did u find any solution ?
"
"
<table>
<tr>
<apex:repeat var="int" value="{!Ints}" >
<td>
<apex:outputText escape="false" value="</tr><tr>" rendered="{!if(mod(cols,4)=0,true,false)}" />
<apex:variable var="cols" value="{!cols+1}" />
</td>
</apex:repeat>
</tr>
</table>