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
Ashritha ReddyAshritha Reddy 

page block table vs data table

what is the main usage ofapec page block table and data table can any one give me the examples?
Best Answer chosen by Ashritha Reddy
Amit Chaudhary 8Amit Chaudhary 8
Apex:dataTable -
An HTML table that is defined by iterating over a set of data, displaying information about one item of data per row. The body of the < apex:dataTable > contains one or more column components that specify what information should be displayed for each item of data. The data set can include up to 1,000 items.
  • ->no need to write inside <apex:pageblock> or <apex:pageblocksection>
  • -> there is no required value
  • -> the data can be displayed using custom styles
  • -> we need to specify column headers explicitly
 
Apex:pageBlockTable – A list of data displayed as a table within either an < apex:pageBlock > or < apex:pageBlockSection > component, similar to a related list or list view in a standard Salesforce page. Like an < apex:dataTable >, an < apex:pageBlockTable > is defined by iterating over a set of data, displaying information about one item of data per row. The set of data can contain up to 1,000 items.The body of the < apex:pageBlockTable > contains one or more column components that specify what information should be displayed for each item of data, similar to a table. Unlike the < apex:dataTable > component, the default styling for < apex:pageBlockTable > matches standard Salesforce styles. Any additional styles specified with < apex:pageBlockTable > attributes are appended to the standard Salesforce styles.
  •  ->pageblocktable should be inside of <apex:pageblock> or <apex:pageblocksection>
  • -><apex:pageblocktable> has a required attribute called "value"
  • ->it uses the standard salesforce page styles
  • ->column headers will be displayed automatically

Apex:repeat – This tag is used as for loop(for list) in apex. You can iterate a list.
  • -> there is no proper allignment of data in repeat as compared with datatable
Please check below post for code
1) http://www.thephani.com/difference-between-pageblocktabe-datatable-repeat/
2) http://honeysalesforce.blogspot.in/2013/02/difference-between-pageblocktabledatata.html

Visualforce page:
<apex:page controller="sample" sidebar="false" >
<style type="text/css">
    .outBorder
    {
        border:3px outset black;
    }
    
    .inBorder
    {
        border-top:3px dotted black;
        border-left:3px dotted black;
    }    
</style>
    <apex:pageBlock title="Pageblock Table">
        <apex:pageblockTable value="{!acc}" var="a">
            <apex:column value="{!a.Name}"/>
            <apex:column value="{!a.Name}"/>            
        </apex:pageblockTable>
    </apex:pageBlock>
    
    <apex:pageBlock title="Data Table">
        <apex:dataTable value="{!acc}" var="a" styleClass="outBorder" width="550px">
            <apex:column styleClass="inBorder">
                <apex:facet name="header">Account Name</apex:facet>
                <apex:outputText >{!a.Name}</apex:outputText>
            </apex:column>       
            <apex:column styleClass="inBorder">
                <apex:facet name="header">Account Number</apex:facet>
                <apex:outputText >{!a.AccountNumber}</apex:outputText>
            </apex:column>              
        </apex:dataTable>
    </apex:pageBlock>    
</apex:page>

Apex Controller:

 public with sharing class sample
{

    public List<Account> acc {get;set;}
    public sample()
    {
        acc = [SELECT Name, AccountNumber FROM Account];
    }  
    
}

Let us know if this will help you
 

All Answers

shiva pendemshiva pendem
HI Ashritha Reddy,

Find the Below Link:

https://developer.salesforce.com/forums/?id=906F00000008rVgIAI

Thanks,
Shiva
Amit Chaudhary 8Amit Chaudhary 8
Apex:dataTable -
An HTML table that is defined by iterating over a set of data, displaying information about one item of data per row. The body of the < apex:dataTable > contains one or more column components that specify what information should be displayed for each item of data. The data set can include up to 1,000 items.
  • ->no need to write inside <apex:pageblock> or <apex:pageblocksection>
  • -> there is no required value
  • -> the data can be displayed using custom styles
  • -> we need to specify column headers explicitly
 
Apex:pageBlockTable – A list of data displayed as a table within either an < apex:pageBlock > or < apex:pageBlockSection > component, similar to a related list or list view in a standard Salesforce page. Like an < apex:dataTable >, an < apex:pageBlockTable > is defined by iterating over a set of data, displaying information about one item of data per row. The set of data can contain up to 1,000 items.The body of the < apex:pageBlockTable > contains one or more column components that specify what information should be displayed for each item of data, similar to a table. Unlike the < apex:dataTable > component, the default styling for < apex:pageBlockTable > matches standard Salesforce styles. Any additional styles specified with < apex:pageBlockTable > attributes are appended to the standard Salesforce styles.
  •  ->pageblocktable should be inside of <apex:pageblock> or <apex:pageblocksection>
  • -><apex:pageblocktable> has a required attribute called "value"
  • ->it uses the standard salesforce page styles
  • ->column headers will be displayed automatically

Apex:repeat – This tag is used as for loop(for list) in apex. You can iterate a list.
  • -> there is no proper allignment of data in repeat as compared with datatable
Please check below post for code
1) http://www.thephani.com/difference-between-pageblocktabe-datatable-repeat/
2) http://honeysalesforce.blogspot.in/2013/02/difference-between-pageblocktabledatata.html

Visualforce page:
<apex:page controller="sample" sidebar="false" >
<style type="text/css">
    .outBorder
    {
        border:3px outset black;
    }
    
    .inBorder
    {
        border-top:3px dotted black;
        border-left:3px dotted black;
    }    
</style>
    <apex:pageBlock title="Pageblock Table">
        <apex:pageblockTable value="{!acc}" var="a">
            <apex:column value="{!a.Name}"/>
            <apex:column value="{!a.Name}"/>            
        </apex:pageblockTable>
    </apex:pageBlock>
    
    <apex:pageBlock title="Data Table">
        <apex:dataTable value="{!acc}" var="a" styleClass="outBorder" width="550px">
            <apex:column styleClass="inBorder">
                <apex:facet name="header">Account Name</apex:facet>
                <apex:outputText >{!a.Name}</apex:outputText>
            </apex:column>       
            <apex:column styleClass="inBorder">
                <apex:facet name="header">Account Number</apex:facet>
                <apex:outputText >{!a.AccountNumber}</apex:outputText>
            </apex:column>              
        </apex:dataTable>
    </apex:pageBlock>    
</apex:page>

Apex Controller:

 public with sharing class sample
{

    public List<Account> acc {get;set;}
    public sample()
    {
        acc = [SELECT Name, AccountNumber FROM Account];
    }  
    
}

Let us know if this will help you
 
This was selected as the best answer