DataTable - Group DataTable column headers and footers can be combined for grouped display.
Sales/Profits of Manufacturers
ManufacturerSale Rate
SalesProfit
Last YearThis YearLast YearThis Year
Totals:\$497,097\$542,317
Apple41%12%$93,280.00$31,007.00
Samsung6%14%$32,324.00$46,974.00
Microsoft69%57%$52,444.00$759.00
Philips53%61%$53,509.00$40,815.00
Sony9%85%$21,681.00$75,097.00
LG12%72%$56,648.00$45,827.00
Sharp32%88%$54,124.00$86,876.00
Panasonic35%12%$46,173.00$71,031.00
HTC63%32%$54,731.00$51,768.00
Nokia18%90%$32,183.00$92,163.00
Dynamic Columns
PlayerGoals
20102011201220132014
Lionel Messi2326331710
Cristiano Ronaldo3718352335
Arjen Robben406362720
Franck Ribery291811154
Ronaldinho374681036
Luis Suarez3038411513
Sergio Aguero2146222529
Zlatan Ibrahimovic7270143
Neymar Jr452030247
Andres Iniesta2234372239
   
<h:form>
    <p:dataTable var="sale" value="#{dtGroupView.sales}">
        <f:facet name="header">
            Sales/Profits of Manufacturers
        </f:facet>

        <p:columnGroup type="header">
            <p:row>
                <p:column rowspan="3" headerText="Manufacturer" />
                <p:column colspan="4" headerText="Sale Rate" />
            </p:row>
            <p:row>
                <p:column colspan="2" headerText="Sales" />
                <p:column colspan="2" headerText="Profit" />
            </p:row>
            <p:row>
                <p:column headerText="Last Year" />
                <p:column headerText="This Year" />
                <p:column headerText="Last Year" />
                <p:column headerText="This Year" />
            </p:row>
        </p:columnGroup>

        <p:column>
            <h:outputText value="#{sale.manufacturer}" />
        </p:column>
        <p:column>
            <h:outputText value="#{sale.lastYearProfit}%" />
        </p:column>
        <p:column>
            <h:outputText value="#{sale.thisYearProfit}%" />
        </p:column>
        <p:column>
            <h:outputText value="#{sale.lastYearSale}">
                <f:convertNumber type="currency" currencySymbol="$" />
            </h:outputText>
        </p:column>
        <p:column>
            <h:outputText value="#{sale.thisYearSale}">
                <f:convertNumber type="currency" currencySymbol="$" />
            </h:outputText>
        </p:column>

        <p:columnGroup type="footer">
            <p:row>
                <p:column colspan="3" style="text-align:right" footerText="Totals:" />
                <p:column footerText="$#{dtGroupView.lastYearTotal}" />

                <p:column footerText="$#{dtGroupView.thisYearTotal}" />
            </p:row>
        </p:columnGroup>

        <f:facet name="footer">
            Data between 2013-2014
        </f:facet>
    </p:dataTable>

    <p:dataTable var="player" value="#{dtGroupView.players}" style="margin-top:40px">
        <f:facet name="header">
            Dynamic Columns
        </f:facet>

        <p:columnGroup type="header">
            <p:row>
                <p:column rowspan="2" headerText="Player" />
                <p:column colspan="#{dtGroupView.yearCount}" headerText="Goals" />
            </p:row>
            <p:row>
                <ui:repeat value="#{dtGroupView.years}" var="year">
                    <p:column headerText="#{year}" />
                </ui:repeat>
            </p:row>
        </p:columnGroup>

        <p:column>
            <h:outputText value="#{player.name}" />
        </p:column>

        <p:columns value="#{dtGroupView.years}" var="year">
            <h:outputText value="#{player.getGoals(year)}" />
        </p:columns>

        <f:facet name="footer">
            Data between 2010-2014
        </f:facet>
    </p:dataTable>
</h:form>
                
PrimeTek, Copyright © 2017
All rights reserved.
Running PrimeFaces-6.2-SNAPSHOT on Mojarra-2.3.2.