Find your content:

Search form

You are here

How do I create a table with more than one column from a single list?


I have code such as the following:

<apex:dataTable value="{!myContacts}" var="c" columns="3">
        <apex:outputText value="{!c.FirstName}"/><br />
        <apex:outputText value="{!c.LastName}"/><br />
        <apex:outputText value="{!c.Email}"/><br />
    <br />

This will display something like:





I want to display myList across N (e.g., 3, 4, etc.) different columns, so that the result is like the following (N=3 in this case). Note that the number of columns is not the same as the number of items on the list.

John              Sue                Joe
Smith             Jones              Mack


How can this be done? Preferably there's just some attribute of apex:dataTable or other apex component tag staring me in the face that I'm missing.

Note that specifying columns="3" on the apex:dataTable has no effect -- still just one column.


Attribution to: Peter Knolle

Possible Suggestion/Solution #1

There are a couple of solutions I've seen:

The Salesforce guide they point out a property, columns, that sets the number of columns in the table. The developer board shows a solution with a custom controller that sets the number of columns dynamically.

Attribution to: Mike Chale

Possible Suggestion/Solution #2

The description in the developers guide doesn't make sense to me based on how it functions, but the rowspan attribute on apex:column gets this done:

<apex:dataTable value="{!myContacts}" var="c">
    <apex:column rowspan="{!myContacts.size}">
        <apex:outputText value="{!c.FirstName}" /><br />
        <apex:outputText value="{!c.LastName}"/><br />
        <apex:outputText value="{!c.Email}"/><br />

Attribution to: Phil Rymek

Possible Suggestion/Solution #3

Unless you need to use the datatable tag for some other reason, this could be done with <apex:repeat> and html table tags:

    <apex:repeat value="{!myContacts}" var="c" />
        <apex:outputText value="{!c.FirstName}"/><br />
        <apex:outputText value="{!c.LastName}"/><br />
        <apex:outputText value="{!c.Email}"/><br />

Attribution to: Jeremy Nottingham
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content