Activity Forums Salesforce® Discussions In Salesforce, how to display dynamic table records in horizontal format?

  • Vikas Kumar

    Member
    January 24, 2017 at 5:18 am

    Hi pranav ,

    public class RowWrapper
    {
    // the values (cells) making up this row
    public List<String> values {get; set;}

    // constructor
    public RowWrapper()
    {
    values=new List<String>();
    }

    // append a value (cell) to the row
    public void addValue(String value)
    {
    values.add(value);
    }
    }

    public List<Account> getAccounts()
    {
    if (null==accs)
    {
    accs=[select id, Name, BillingStreet, BillingCity, BillingPostalCode from Account
    where BillingCity != null and BillingPostalCode!=null limit 3];
    }

    return accs;
    }

    // retrieves the list of row wrappers
    public List<RowWrapper> getRowWrappers()
    {
    if (null==rows)
    {
    rows=new List<RowWrapper>();

    // create a row for each field - there are 4 of these, Name, Street, City and PostCode
    for (Integer idx=0; idx<4; idx++)
    {
    rows.add(new RowWrapper());
    }

    // iterate the accounts and populate the rows
    for (Integer idx=0; idx<getAccounts().size(); idx++)
    {
    rows[0].addValue(getAccounts()[idx].Name);
    rows[1].addValue(getAccounts()[idx].BillingStreet);
    rows[2].addValue(getAccounts()[idx].BillingCity);
    rows[3].addValue(getAccounts()[idx].BillingPostalCode);
    }
    }

    return rows;
    }

    Vf Page

    <table class="list" border="0" cellpadding="0" cellspacing="0">
    <tr class="headerRow ">
    <apex:repeat value="{!headWrap.values}" var="heading">
    <th class="headerRow ">
    {!heading}
    </th>
    </apex:repeat>
    </tr>
    <apex:repeat value="{!rowWrappers}" var="row">
    <tr>
    <apex:repeat value="{!row.values}" var="value">
    <td>
    {!value}
    </td>
    </apex:repeat>
    </tr>
    </apex:repeat>
    </table>

    Go through This Blog

    http://bobbuzzard.blogspot.in/2010/09/rotating-visualforce-table.html

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos