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
Anindya Halder 6Anindya Halder 6 

Columns attribute of <apex:dataTable> is not working

Hello All,
I am very new to salesforce. I amtrying to display data in tabular format - in three columns

           <apex:dataTable id="theTable" value="{!viewstate.GLAs}" var="glaState" styleClass="largerLabel" columns="{!viewstate.Columns}">
                <apex:column>         
                        <apex:inputCheckbox id="glaCheck" value="{!glaState.glaChecked}"/>
                        <label for="glaCheck"  class="noSubLabel">{!glaState.GLAName}</label>
                </apex:columnn>    
            </apex:dataTable>

In viewstate , getColumns will return 3 .

But all my data is being displayed in one single column.

Please help.
Best Answer chosen by Anindya Halder 6
surasura
<apex:column> represents a <td> so if you want data in seperate columns you have to bind those to spereate <apex:columns> plese see  the example below
<apex:dataTable value="{!accounts}" var="account" id="theTable" >

	

		<apex:column>

		        <apex:facet name="header">Name</apex:facet>

			

			<apex:outputText value="{!account.name}"/>

		</apex:column>

		<apex:column>

			<apex:facet name="header">Owner</apex:facet>


			<apex:outputText value="{!account.owner.name}"/>

		</apex:column>

	</apex:dataTable>

 

All Answers

surasura
<apex:column> represents a <td> so if you want data in seperate columns you have to bind those to spereate <apex:columns> plese see  the example below
<apex:dataTable value="{!accounts}" var="account" id="theTable" >

	

		<apex:column>

		        <apex:facet name="header">Name</apex:facet>

			

			<apex:outputText value="{!account.name}"/>

		</apex:column>

		<apex:column>

			<apex:facet name="header">Owner</apex:facet>


			<apex:outputText value="{!account.owner.name}"/>

		</apex:column>

	</apex:dataTable>

 
This was selected as the best answer
Rahul JagtapRahul Jagtap
You can use "apex:repeat" tag to repeat your columns. This will help you out.

e.g.
<apex:pageBlockTable value="{!cases}" var="cas" rendered="{!exportToExcel}">  
                <apex:column headerValue="Case Number">      
                         <apex:outputLink target="_blank" value="/{!cas.id}">"{!cas.caseNumber}" </apex:outputLink>
                </apex:column>                                
                  <apex:repeat value="{!$ObjectType.case.fieldsets.Case_Report_Fieldset}" var="fieldValue">
                     <apex:column value="{!cas[fieldValue]}">
                     </apex:column>
                 </apex:repeat>                                                           
            </apex:pageBlockTable>

 
Anindya Halder 6Anindya Halder 6
Hi , Using <apex:repeat> or writing <apex:Column> 3 times renders same result - It repeats the same value 3 times....

Like

1000     1000   1000
2000     2000   2000
3000     3000   3000
4000     4000   4000

But I want to display in this format
1000     2000   3000
4000
Anindya Halder 6Anindya Halder 6
Hi,
Thanks for all your help . <apex:dataTable> does not work the way I was thinking . @Sura was right , if I want to display data in three separate columns I need to bind them separately .

I could not harcode the number of <apex:columns> or <tr><td> because its according to the size of the list my controller is returning.

I changed in the controller - instead of returning a list of objects(List of GLAs) , I made a list of lists - where each innerlists consists of three Objects(GLAs in this case) and then could use the code properly

<apex:dataTable id="theTable" value="{!viewstate.ListGLAs}" var="listGLA" styleClass="largerLabel" columns="3" width="100%">  
        <apex:repeat value="{!listGLA}" var="glaState">
        <apex:column>         
               <apex:inputCheckbox id="glaCheck" value="{!glaState.glaChecked}"/>
               <label for="glaCheck"  class="noSubLabel">{!glaState.GLAName}</label>
        </apex:column>
        </apex:repeat>
</apex:dataTable>