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
vishesh91vishesh91 

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.

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

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

Navatar_DbSupNavatar_DbSup

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. 

This was selected as the best answer
Mitesh SuraMitesh Sura

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

 <apex:pageBlock >
   <apex:pageBlockTable value="{!wObjs}" var="wObj"> 
     <!-- Fields -->
     <apex:repeat value="{!wObj.wFields}" var="f">
        <apex:variable value="{!f.name}" var="ColName"/> 
	<apex:column headerValue="TEST">
       	   <apex:inputField value="{!wObj.sObj[f.Name]}" required="true" /> 			        		
	</apex:column>
     </apex:repeat>                     
  </apex:pageBlockTable>
</apex:pageBlock>

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