My picklist values:

  1. model,version
  2. model,version,option
  3. model,version,option,discount

If I choose "model,version" the table displayed with 2 columns like model,version.

If I choose "model,version,option" the table displayed with 3 columns named model,version,option and so on

Please can any one suggest me..

closed as unclear what you're asking by BarCotter, Boris Bachovski, Vamsi Krishna, crmprogdev, Chris Duncombe Aug 21 '15 at 13:44

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Closed as unclear? Seems perfectly clear to me. Just what I want to know. – NickJ Sep 4 '17 at 14:58

You can take help of from here

Page Block Tables actually support tags (This was not originally supported). The following example demonstrates 2 ways of accomplishing dynamic columns in a table depending on the type of data you supply.

Using fieldsets is the simplest way to control dynamic columns. This is the best choice if displaying a table of SObjects

<apex:pageBlock id="block">
    <apex:pageBlockTable id="table" var="account" value="{!accounts}">
        <apex:column headerValue="Account Name" value="{!account.Name}" />
        <apex:repeat var="f" value="{!$ObjectType.Account.FieldSets.Example_Fieldset}">
            <apex:column headerValue="{!f.label}">
                <apex:inputField value="{!account[f]}" />

If you are using a List, there is an important gotcha with dynamic tables: header cells are not rendered. The fix is to declare the following css snippet and apply the style as outlined below .empty-column-content { display: none; }

You can also use this approach. more information can be found here

  • Incorrect parameter type for subscript. Expected Number, received Text – Parth Thakkar Mar 22 at 9:44

In your controller:

public String picklistValue {get; set;}
public String[] getFields() {
    return picklistValue.split(',');

then in the page the columns displayed can be driven by the SObject field API names:

<apex:pageBlockTable var="sob" value="{!sobs}">
    <apex:repeat var="f" value="{!fields}">
        <apex:column value="{!sob[f]}"/>

You will need to re-render the table when the picklist changes (use e.g. an onchange apex:actionSupport).

Also unless you are using an object for which the API names of the fields are OK to display in the picklist, you will need to map from a label shown in the picklist (e.g. "Version") to the API name (e.g. "Version__c").

Not the answer you're looking for? Browse other questions tagged or ask your own question.