Play Games

Search This Blog

Friday, November 13, 2015

Nested Page block table (Display all accounts along with its contacts in visualforce page)

BreakBefore attribute in <apex:column> : A Boolean value that specifies whether the
 column should begin a new row in the table. If set to true, the column begins a new row.
Apex Class:
public class AccountAndContactsDisplay {
    public list<Account> accountList {get;set;}
    public AccountAndContactsDisplay () {
    }
    public void displayAccounts() {
        accountList = [select id,name,(select id,name from contacts) from Account limit 5];
    }
}
Visualforce Page:
<apex:page controller="AccountAndContactsDisplay" action="{!displayAccounts}">
    <apex:pageBlock title="Account and its Contacts">
        <apex:pageBlockTable value="{!accountList}" var="acc">
            <apex:column value="{!acc.name}" headerValue="Account Name"/>
            <apex:column breakBefore="true">
                <apex:pageBlock title="{!acc.name} related Contact Details">
                    <apex:pageBlockTable value="{!acc.contacts}" var="con" >
                        <apex:column value="{!con.name}" headerValue="Contact Name"/>
                    </apex:pageBlockTable>
                </apex:pageBlock>  
            </apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
Output :

1 comment: