You need to sign in to do that
Don't have an account?
vishesh91
dynamic columns in pageblock table visualforce
hi I have a situation like this : my vf page gets a list of users from the controller.I want to display user information in a pageblock table.number of fields which each user element has is not known,so the number of columns to be displayed in page block table is not known.
<apex:pageBlockTable value="{!userList}" var="myUser" id="table"> <apex:column value="{!myUser.field1}" /> <apex:column value="{!myUser.field2}" /> <apex:column value="{!myUser.fieldn}" /> </apex:pageBlockTable>
here the number of fields and their names(field1,field2.......fieldn.....) are to be determined dynamically. I am stuck,any idea will be of great help
thanks.
Hi,
You can access the field of user object like an array
Try the below code snippet as reference:
<apex:pageBlockTable value="{!objectforquery}" var="displaydata">
<apex:repeat value="{!fieldapiname}" var="displayfieldname">
<apex:column value="{!displaydata[displayfieldname]}"/>
</apex:repeat>
</apex:pageBlockTable>
</apex:pageBlock>
Use the below link as reference:
http://boards.developerforce.com/t5/Apex-Code-Development/Getting-pages-classes-Trigers-users-recordtypes-Dynamically/m-p/443021#M80554
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
Hi,
You can access the field of user object like an array
Try the below code snippet as reference:
<apex:pageBlockTable value="{!objectforquery}" var="displaydata">
<apex:repeat value="{!fieldapiname}" var="displayfieldname">
<apex:column value="{!displaydata[displayfieldname]}"/>
</apex:repeat>
</apex:pageBlockTable>
</apex:pageBlock>
Use the below link as reference:
http://boards.developerforce.com/t5/Apex-Code-Development/Getting-pages-classes-Trigers-users-recordtypes-Dynamically/m-p/443021#M80554
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Navatar_DbSup,
Thanks for posting this. It did help me in displaying the columns dynamically, but I cannot column header is always blank.
below is snippet of my VF page
I tried with<apex:variable> and hard coded "TEST" too, but nothing seems to work. <inputField> works fine though.
I have spent almost 2 days in getting headerValue populated dynamically, now I give up.
Thank you for your time.
regards
ISVForce Partner
Check out this post:
http://salesforce.stackexchange.com/questions/245/dynamic-number-of-columns-in-a-pageblocktable
Tau