0

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..

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

2 Answers 2

1

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]}" />
            </apex:column>
        </apex:repeat>
    </apex:pageBlockTable>
</apex:pageBlock>

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

1
  • Incorrect parameter type for subscript. Expected Number, received Text Commented Mar 22, 2019 at 9:44
1

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]}"/>
    </apex:repeat>
</apex:pageBlockTable>

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 .