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:\$457,090\$236,343
Apple68%57%$58,380.00$24,519.00
Samsung71%64%$5,190.00$12,753.00
Microsoft47%85%$96,536.00$13,403.00
Philips98%71%$40,685.00$69,318.00
Sony58%30%$8,306.00$12,809.00
LG6%38%$65,198.00$3,902.00
Sharp1%62%$95,017.00$19,259.00
Panasonic92%95%$43,354.00$41,382.00
HTC43%10%$16,959.00$4,116.00
Nokia46%33%$27,465.00$34,882.00
Dynamic Columns
PlayerGoals
20102011201220132014
Lionel Messi384803625
Cristiano Ronaldo365173631
Arjen Robben381131632
Franck Ribery187392245
Ronaldinho2637313826
Luis Suarez922331917
Sergio Aguero272229110
Zlatan Ibrahimovic284726510
Neymar Jr314313493
Andres Iniesta204428838
<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>