I do not want to resort to HTML. How to merge cells in <apex:panelGrid>
?
The below diagram shows column span merge using HTML tables. How to do both, column and row span merge, using Visualforce components only?
You can't merge the cells. But you can play with columns
parameter and nesting another panel grid into the first one, but with a different columns number. Here is my example:
<style>
.colClass{
width:50%;
padding: 5px;
}
.myHeader {
background: #cecece;
font-weight: bold;
}
</style>
<apex:panelGrid columns="1" width="500" cellpadding="0" cellspacing="0" rules="all" frame="box">
<!-- The first column -->
<apex:panelGrid columns="2" width="100%" cellpadding="0" cellspacing="0" rules="all">
<!-- Output panel used to be able to layout the row -->
<apex:outputPanel style="padding:5px;" layout="block" styleClass="myHeader">
<apex:outputText value="Header 1"/>
</apex:outputPanel>
<!-- Another header column -->
<apex:outputPanel style="padding:5px;" layout="block" styleClass="myHeader">
<apex:outputText value="Header 2"/>
</apex:outputPanel>
<apex:panelGrid columns="2" width="100%" cellpadding="0" cellspacing="0" rules="all" columnClasses="colClass">
<apex:outputText value="Text 1"/>
<apex:outputText value="Text 2"/>
</apex:panelGrid>
<apex:outputPanel style="padding:5px;" layout="block">
<apex:outputText value="Text 3"/>
</apex:outputPanel>
</apex:panelGrid>
<!-- Merged header -->
<apex:panelGroup layout="block" style="width:100%;" styleClass="myHeader">
<apex:outputPanel style="padding:5px;" layout="block">
<apex:outputText value="Header 3"/>
</apex:outputPanel>
</apex:panelGroup>
<apex:panelGrid columns="1" width="100%" cellpadding="0" cellspacing="0" rules="all" columnClasses="colClass">
<apex:outputText value="Text 4"/>
<apex:outputText value="Text 5"/>
</apex:panelGrid>
</apex:panelGrid>
Result:
You cannot use spanning columns in an apex:panelGrid. You should instead use a normal HTML table. Nesting managed elements (those with a namespace like apex or c) will bloat your view state size unnecessarily.