function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kishore64kishore64 

Hw to display columns horizontally in a table

Hi buddies,

I was not able to display records in horizontally.
Ex : In a table am retrieving phone,email from contact. Now i want to show phone,Email in horizontally.

Normally we can show them in columns, but my client needs thus to be display in horizontally.

Phone   98451212312      9876789989         9888999999
Email    test@test.com      test1@tes.com     test2@test.com

Waiting for your respnse buddies.
bob_buzzardbob_buzzard
Essentially you want to rotate the table, displaying columns in rows.  My very first blog post covered this :

http://bobbuzzard.blogspot.co.uk/2010/09/rotating-visualforce-table.html
kishore64kishore64
Hi bob_buzzard,

This solution was very good but i was not able to pass values in first column such that
Account Name, BillingStreet, BillingCity, BillingPostalCode. With this we can understand first row is for name and like that.

Can you help me out, plz.
kishore64kishore64
Ho Buddy,

Its resolved and everything coming in a good manner but in pdf  these are not coming. 
Withour pdf it is shwoing correctly what exactly we needed but when i save it as pdf it throws error like : 
PDF generation failed. Check the page markup is valid.

Can you check it once.
bob_buzzardbob_buzzard
Check the visualforce developers guide for valid/invalid components when generating PDF.  Otherwise you'll need to start commenting out chunks of your markup to narrow down the issue.
sunny522sunny522
Hi Kishore64,
         "PDF generation failed. Check the page markup is valid." :This type of errors occur when we use normal visualforce page tags like <apex:form> and so on.so, once remove this type of tags and use basic html tags and try.you will get what you want.

if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Ravi NarayananRavi Narayanan
You can use WrapperClass
kishore64kishore64
Hi Sunny522,

        Here i am using HTML tags only. I am not using any Visualforce Page Tags then how can rectify that error .

Help me out .

sunny522sunny522
Hi Kishore64,
    Can u post the full code that you used so that I can go through that code and find where the issue is.once I resoved this issue by using html tags
kishore64kishore64
This is vf page code:

<apex:page controller="cls_printpage1" sidebar="false" showHeader="false" renderAs="pdf">
<table class="list" border="1" cellpadding="0" cellspacing="0">

    <apex:repeat value="{!rowWrappers}" var="row">
       <tr>
         <apex:repeat value="{!row.labels}" var="label">          
           <td>
            <b>{!label}</b>
           </td>
         </apex:repeat>
         <apex:repeat value="{!row.values}" var="value">          
           <td>
             {!value}
           </td>
         </apex:repeat>
       </tr>
    </apex:repeat>
  </table>
</apex:page>


This is controller code:

public class cls_printpage1 {
    // retrieves the list of accounts backing the page
    Public List<Account> accs;
    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
List<RowWrapper> rows;
    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<5; idx++)
            {
                rows.add(new RowWrapper());
            }
            
            // iterate the accounts and populate the rows
            for (Integer idx=0; idx<getAccounts().size(); idx++)
            {
               // rows[0].addValue('Name');
                rows[0].addValue(getAccounts()[idx].Name);
               
              //  rows[1].addValue('BillingStreet');
                rows[1].addValue(getAccounts()[idx].BillingStreet);
               
              //  rows[2].addValue('BillingCity');
                rows[2].addValue(getAccounts()[idx].BillingCity);
               
              //  rows[3].addValue('BillingPostalCode');
                rows[3].addValue(getAccounts()[idx].BillingPostalCode);
            }
       
             rows[0].addLabels('Name');
             rows[1].addLabels('BillingStreet');
             rows[2].addLabels('BillingCity');
             rows[3].addLabels('Billling PostalCode');
        }
        
        return rows;
    }
   
    public class RowWrapper
    {
     // the values (cells) making up this row
     public List<String> values {get; set;}
    
     public List<String> labels {get; set;}
     // constructor
     public RowWrapper()
     {
      values=new List<String>();
      labels=new List<String>();
     }
     
     // append a value (cell) to the row
     public void addValue(String value)
     {
      values.add(value);
     }
    
     //add all labels to column
     public void addLabels(String value){
      labels.add(value);  
     }
   
    }
}


Check this one and let me know what is the issue where i need to modify it please help out......
sunny522sunny522
Hi Kishore64,
        Here is the modfied vf code.Its working fine now.

<apex:page controller="cls_printpage1" sidebar="false" showHeader="false" renderAs="pdf">
<table class="list" border="1" cellpadding="0" cellspacing="0">

    <apex:repeat value="{!rowWrappers}" var="row">
       <apex:repeat value="{!row.labels}" var="label">
       <tr>
                 
           <td>
            <b>{!label}</b>
           </td>
        
         <apex:repeat value="{!row.values}" var="value">         
           <td>
             {!value}
           </td>
         </apex:repeat>
       </tr>
       </apex:repeat>
    </apex:repeat>
  </table>
</apex:page>

if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

kishore64kishore64
Hi sunny522,

   Thanks a lot. Now it's working fine .......
kishore64kishore64
Hi sunny522,

 here the requuirement is the table should be lke as below

    Size         4 x 5     2 x 3      5 x 6
   Guage      120        60        120

But ourr code will display like this 

    Size          4 x         2 x         5 x 
                       5            3            6
   Guage      120        60        120



<table class="list" border="1" cellpadding="0" cellspacing="0">
   <apex:repeat value="{!rowWrappers}" var="row">
       <apex:repeat value="{!row.labels}" var="label">
       <tr>
           <td style="padding:0 15px 0 15px;">
            <b>{!label}</b>
           </td>
         <apex:repeat value="{!row.values}" var="value">        
           <td style="padding:0 30px 0 30px;" align="left">
             {!value}
           </td>
         </apex:repeat>
       </tr>
       </apex:repeat>
    </apex:repeat>
  </table>


how can i chage this format to that format please help me out .....

Ravi NarayananRavi Narayanan
account Details:

abcd,billingcity,address
efgh,billingcity,address

you want to display in table like below

abcd                             efgh
billingcity                      billingcity
address                       address

is this what you are looking for?
kishore64kishore64
Hi Ravi Narayanan, 

      I want to display like below

    Size         4 x 5     2 x 3      5 x 6
   Guage      120        60        120

But my code will display like this

    Size          4 x         2 x         5 x
                       5            3            6
   Guage      120        60        120


so, where i need to modify it ?

sunny522sunny522
Hi Kishore64,
     I have no clarity how you are getting size values.If possible post sample code.I will go through it and resolve.I think while adding size values to wrapper class,take size value in string and add.