Search In This Blog

2016-10-29

Output data in 3 columns by repeat in Visualforce


There're a lot way to output a list of strings in 3 columns, like 3*n.

Here are two ways.

First need to get the value of list before output, list should be able to public get. Here is an example.
// [sample] string[]
public String[] getSampleStrings() {
    return new String[]{'ONE','TWO','THREE','FOUR','FIVE','SIX','SEVEN','EIGHT','NINE'};
}
Way 1: Use first and rows in apex:outputPanel
// Repeat sample start (by first and rows)
<apex:outputpanel layout="block">
    <apex:repeat first="1" rows="3" value="{!sampleStrings}" var="sampStr">
        <apex:outputtext style="padding: 0 10px;" value="{!sampStr}">
    </apex:outputtext></apex:repeat>
</apex:outputpanel>
<apex:outputpanel layout="block">
    <apex:repeat first="4" rows="3" value="{!sampleStrings}" var="sampStr">
        <apex:outputtext style="padding: 0 10px;" value="{!sampStr}">
    </apex:outputtext></apex:repeat>
</apex:outputpanel>