Skip to main content
replaced http://salesforce.stackexchange.com/ with https://salesforce.stackexchange.com/
Source Link

You can take help of from here

Page Block Tables actually support apex:repeat 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; }

<apex:pageBlock id="block2"> <apex:pageBlockTable id="table" var="row" value="{!rows}"> <apex:repeat var="cell" value="{!row.cells}"> <apex:column headerValue="No matter how this is defined, it results in an empty cell"> <apex:outputText value="{!cell}" /> </apex:column> </apex:repeat> <apex:repeat var="header" value="{!headers}"> <apex:column headerValue="{!header}" styleClass="empty-column-content" /> </apex:repeat> </apex:pageBlockTable> </apex:pageBlock>

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

You can take help of from here

Page Block Tables actually support apex:repeat 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; }

<apex:pageBlock id="block2"> <apex:pageBlockTable id="table" var="row" value="{!rows}"> <apex:repeat var="cell" value="{!row.cells}"> <apex:column headerValue="No matter how this is defined, it results in an empty cell"> <apex:outputText value="{!cell}" /> </apex:column> </apex:repeat> <apex:repeat var="header" value="{!headers}"> <apex:column headerValue="{!header}" styleClass="empty-column-content" /> </apex:repeat> </apex:pageBlockTable> </apex:pageBlock>

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

You can take help of from here

Page Block Tables actually support apex:repeat 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; }

<apex:pageBlock id="block2"> <apex:pageBlockTable id="table" var="row" value="{!rows}"> <apex:repeat var="cell" value="{!row.cells}"> <apex:column headerValue="No matter how this is defined, it results in an empty cell"> <apex:outputText value="{!cell}" /> </apex:column> </apex:repeat> <apex:repeat var="header" value="{!headers}"> <apex:column headerValue="{!header}" styleClass="empty-column-content" /> </apex:repeat> </apex:pageBlockTable> </apex:pageBlock>

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

Source Link
Tushar Sharma
  • 29.7k
  • 7
  • 38
  • 60

You can take help of from here

Page Block Tables actually support apex:repeat 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; }

<apex:pageBlock id="block2"> <apex:pageBlockTable id="table" var="row" value="{!rows}"> <apex:repeat var="cell" value="{!row.cells}"> <apex:column headerValue="No matter how this is defined, it results in an empty cell"> <apex:outputText value="{!cell}" /> </apex:column> </apex:repeat> <apex:repeat var="header" value="{!headers}"> <apex:column headerValue="{!header}" styleClass="empty-column-content" /> </apex:repeat> </apex:pageBlockTable> </apex:pageBlock>

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