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
KML1234KML1234 

Column headings for a panelGrid?

Can anyone tell me how to code column headings for a panelGrid?

The documentation seems to suggest that it's done with a <apex:facet name="header"> component. The dataTable component is given as an example, but it relies on the <apex:column> component which is not applicable to a panelGrid.

My panelGrid has 4 columns and I'd like to add a different header to each column. I'm expecting the panelGrid to generate the following html:

Code:
<tr><th>Heading 1</th><th>Heading 2</th><th>Heading 3</th><th>Heading 4</th></tr>

How should it be done?

Thanks.
Best Answer chosen by Admin (Salesforce Developers) 
jwetzlerjwetzler
You do want to use the facet component for the header, but as far as I know there is not a way to split header amongst the columns.  The header will generate a th with a colspan of 4 (or the number of columns you've defined in your panelGrid).

So I think either you have to use the header facet and mess with the styling, or you should just add your four headers in as the first four child components.  With the latter option it will handle your spacing correctly, you'll just get td's instead of th's.

Code:
<apex:page showHeader="false">
  <apex:panelGrid columns="4">
  
    <apex:outputText value="header one" style="font-weight: bold"/>
    <apex:outputText value="header two" style="font-weight: bold"/>
    <apex:outputText value="header three" style="font-weight: bold"/>
    <apex:outputText value="header four" style="font-weight: bold"/> 

    <apex:outputText value="one"/>
    <apex:outputText value="two"/>
    <apex:outputText value="three"/>
    <apex:outputText value="four"/>
    
    <apex:outputText value="one"/>
    <apex:outputText value="two"/>
    <apex:outputText value="three"/>
    <apex:outputText value="four"/>

  

  </apex:panelGrid>
</apex:page>