+ Start a Discussion
smitrasmitra 

Displaying SOQL query result in VF page tablular form

Please let me know how to display the SOQL query result in VF page in tabular form when the SOQL object type and the associated attributes are dynamic.




Best Answer chosen by smitra
Ankit AroraAnkit Arora
I've blogged this, how to create dynamic table with dynamic columns. Let me know if it helps.

http://forceguru.blogspot.in/2012/11/page-block-table-with-dynamic-columns.html

All Answers

Ankit AroraAnkit Arora
I've blogged this, how to create dynamic table with dynamic columns. Let me know if it helps.

http://forceguru.blogspot.in/2012/11/page-block-table-with-dynamic-columns.html
This was selected as the best answer
jo devjo dev
Hi,here i attched sample code for tableview


Apex controller code:


public class tableviewcontroller
{
public List<Account> acclist {get;set;}
    public tableviewcontroller()
    {
    acclist=[select id,Name,Phone,Fax from Account];
    }
}



Visualforce page code:



<apex:page controller="tableviewcontroller">
<style>
.Tabletitle
{
background-color: #179dae !important;
font-size:13px;
}
td
{
padding:4px 1px 2px 2px;
}
</style>
     <apex:dataTable value="{!acclist}" var="A" rules="rows">
        <apex:column headerValue="ID" headerClass="Tabletitle" width="240">
            <apex:outputField value="{!A.ID}"/>
        </apex:column>
         <apex:column headerValue="Name" headerClass="Tabletitle" width="240" >
             <apex:outputLabel>{!A.Name}</apex:outputLabel>
         </apex:column>
         <apex:column headerValue="Phone" headerClass="Tabletitle" width="240">
             <apex:outputLabel>{!A.Phone}</apex:outputLabel>
         </apex:column>
          <apex:column headerValue="Fax" headerClass="Tabletitle" width="240">
              <apex:outputLabel>{!A.Fax}</apex:outputLabel>
         </apex:column>
     </apex:dataTable>
</apex:page>
Ankit AroraAnkit Arora
Jo Dev, how is this dynamic? Question was not showing the results in table, it was how to show it dynamically.
smitrasmitra
Thanks Ankit..It worked..