how we can create the data table dynamically in Apex Salesforce ?
Visual Force
<apex:dynamicComponent componentValue="{!pageBlock}" />
Controller Apex Class
public List<Account> lstaccount{get;set;}
Public List<Account> getAccounts(){
lstaccount=[select id,name,type,industry from account Limit 5];
return lstaccount;
}
public Component.Apex.PageBlock getpageBlock()
{
Component.Apex.PageBlock pb=new Component.Apex.PageBlock();
Component.Apex.PageBlockTable ptable=new Component.Apex.PageBlockTable();
ptable.expressions.value='{!accounts}';
ptable.var='a';
ptable.rendered=true;
Component.Apex.Column namecolumn=new Component.Apex.Column();
namecolumn.expressions.value='{!a.name}';
Component.Apex.Column industrycolumn=new Component.Apex.Column();
industrycolumn.expressions.value='{!a.Industry}';
Component.Apex.Column typecolumn=new Component.Apex.Column();
typecolumn.expressions.value='{!a.type}';
pb.childcomponents.add(ptable);
ptable.childcomponents.add(namecolumn);
ptable.childcomponents.add(typecolumn);
ptable.childcomponents.add(industrycolumn);
return pb;
}
No comments:
Post a Comment