I'm using visalforce page and apex class for rendering the table on the browser. I want to display 6 records per row. I have total 4 rows & 5 columns. How I can use the repeat function to limit 6 records per row and remaining will be on next row.

<apex:repeat value="{!Appot}" var="string" id="Vers">
    <td class='tblSet'>
        <apex:outputText value="{!string}" id="T"/>

From apex code I'm passing an array of Integer.

Thanks for help!

  • Does it have to be a table that you're adding it to? If not, a css solution might work for you. – Nick Cook Aug 24 '16 at 3:03

You can use apex:variable to iterate throught your data, and for each sixth element rerender break line

public class repeatCon {
    public String[] getStrings() {
        return new String[]{'one','two','three','four','five','six','seven'};

<apex:page controller="repeatCon" id="thePage">
    <apex:variable var="i" value="{!0}"/>
    <apex:repeat value="{!strings}" var="string">
        <apex:variable var="i" value="{!i+1}"/>
            <apex:outputText value="{!string}"/>&nbsp;
            <apex:outputText value="<br/>" rendered="{!MOD(i, 3)==0}" escape="false"/>


enter image description here

  • The documentation says that reassigning an apex:variable in an iteration component is unsupported. Does it work though? – martin Aug 24 '16 at 3:33
  • @martin, seems working, can differs on version I suppose. Works for 36 and 37 – Ilya Lepesh Aug 24 '16 at 3:36
  • Interesting. They might have updated the functionality without updating their documentation. Otherwise I'm not sure why they went out of their way to say it isn't supported. Good to know it works though. – martin Aug 24 '16 at 3:40

If you want to do this in Visualforce, you could change your data structure from a list of plain Integers to a list of a class that holds the integer and the integer's position in the list.

public class MyController {

    public list<MyInteger> ilist {get; set;}

    public class MyInteger{
        public Integer Index {get; set;}
        public Integer Value {get; set;}
        MyInteger(Integer i, Integer v){Index = i; Value = v;}

    public MyController(){
        ilist = new list<MyInteger>();
        list<Integer> OriginalList = new list<Integer>{42,786,12,2,75,95,654,21,35,78,35,75};
        for (Integer i = 0 ; i < OriginalList.size() ; i++) ilist.add(new MyInteger(i,OriginalList[i]));


Then you could conditionally render a new row for every 6th element in the list.

    <apex:repeat value="{!ilist}" var="i">
        <apex:outputText value="<tr>" escape="false" Rendered="{!MOD(i.Index,6)==0}"/>        

Another idea would be to use a List<List<Type__c>> to hold your values.


//recs = list of your records
List<List<Type__c>> appotList = new List<List<Type__c>>();
for (integer j = 0, index = 0, recSize = recs.size();j < recSize;++index)
    appotList.add(new List<Type__c>());
    for (integer i = 0; i < 6 && j < recSize; ++i)


<apex:repeat value="appotList" var="innerList">
        <apex:repeat value="innerList" var="record">
            <td class='tblSet'>
               <apex:outputText value="{!record}" id="T"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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