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:\$511,602\$515,202
Apple70%1%$36,230.00$59,233.00
Samsung40%29%$37,848.00$84,664.00
Microsoft63%64%$44,391.00$95,351.00
Philips30%62%$65,559.00$7,853.00
Sony26%18%$17,702.00$46,653.00
LG20%74%$51,476.00$26,846.00
Sharp55%23%$77,926.00$24,229.00
Panasonic50%86%$32,219.00$97,915.00
HTC82%51%$50,306.00$64,316.00
Nokia9%47%$97,945.00$8,142.00
Dynamic Columns
PlayerGoals
20102011201220132014
Lionel Messi412713194
Cristiano Ronaldo1538202527
Arjen Robben619352822
Franck Ribery2107373
Ronaldinho2719252816
Luis Suarez463482613
Sergio Aguero451024415
Zlatan Ibrahimovic103433440
Neymar Jr3938251631
Andres Iniesta62019387
   
<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 © 2015
All rights reserved.
Running PrimeFaces-6.1-SNAPSHOT on Mojarra-2.2.8.