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:\$575,917\$580,783
Apple65%10%$32,707.00$91,284.00
Samsung14%56%$55,768.00$90,875.00
Microsoft43%85%$70,329.00$86,317.00
Philips77%68%$84,221.00$27,162.00
Sony46%58%$33,401.00$76,415.00
LG85%48%$70,280.00$425.00
Sharp43%68%$60,969.00$14,313.00
Panasonic35%18%$14,249.00$92,893.00
HTC47%27%$78,865.00$52,838.00
Nokia22%54%$75,128.00$48,261.00
Dynamic Columns
PlayerGoals
20102011201220132014
Lionel Messi3549274339
Cristiano Ronaldo44294512
Arjen Robben422213331
Franck Ribery351515338
Ronaldinho25912130
Luis Suarez3737143740
Sergio Aguero17727234
Zlatan Ibrahimovic12445533
Neymar Jr14313740
Andres Iniesta46503143
<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>