3

Is there a way using JSF to group two or more columns under a single parent column in JSF? I have a dataTableEx with hx:columnEx columns inside of it. What I want is something like this:

 [MAIN HEADER FOR COL1+2   ][Header for Col 3+4]

 [ COL1 Header][COL2 Header][COL3    ][COL 4   ] 

 Data          Data             Data     Data

 Data          Data             Data     Data

 Data          Data             Data     Data

 Data          Data             Data     Data

Data Data Data Data

Thanks

peterh
  • 11,875
  • 18
  • 85
  • 108
Jaime Garcia
  • 6,744
  • 7
  • 49
  • 61

3 Answers3

1

You can probably achieve what you want with the table header, a panelGrid and a little CSS.

<style type="text/css">
.colstyle {
    width: 25%
}
</style>
</head>
<body>

<f:view>
    <h:dataTable border="1" value="#{columnsBean.rows}" var="row"
        columnClasses="colstyle">
        <f:facet name="header">
            <h:panelGrid columns="2" border="1" style="width: 100%">
                <h:outputLabel style="width: 100%" value="MAIN HEADER FOR COL1+2" />
                <h:outputLabel style="width: 100%" value="MAIN HEADER FOR COL3+4" />
            </h:panelGrid>
        </f:facet>
        <h:column>
            <f:facet name="header">
                <h:outputText value="COL1 Header" />
            </f:facet>
            <h:outputLabel value="#{row.col1}" />
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputText value="COL2 Header" />
            </f:facet>
            <h:outputLabel value="#{row.col2}" />
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputText value="COL3 Header" />
            </f:facet>
            <h:outputLabel value="#{row.col3}" />
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputText value="COL4 Header" />
            </f:facet>
            <h:outputLabel value="#{row.col4}" />
        </h:column>
    </h:dataTable>
</f:view>
McDowell
  • 107,573
  • 31
  • 204
  • 267
0

Your best bet is likely to use nested tables for the first header (first header in the outer table, and your second header and data inside a nested table) so that it looks like two headers.

Elie
  • 13,693
  • 23
  • 74
  • 128
0

Maybe you can have a look to advanced components libraries, such as RichFaces that offer more complex structures for datatables, like in this example.

Romain Linsolas
  • 79,475
  • 49
  • 202
  • 273