DataTable - Grouping

DataTable column headers and footers can be grouped for complex display.

Sales/Profits of Manufacturers
ManufacturerSales
Sales CountProfit
Last YearThis YearLast YearThis Year
Totals:534538$439044$
Mercedes 76% 89% 4042$ 30151$
BMW 9% 27% 45826$ 7281$
Volvo 46% 43% 70366$ 47112$
Audi 27% 90% 99811$ 39178$
Renault 44% 68% 53735$ 55772$
Opel 42% 96% 78405$ 48391$
Volkswagen 67% 65% 56114$ 54666$
Chrysler 40% 61% 73316$ 88578$
Ferrari 65% 75% 19331$ 8684$
Ford 62% 7% 33592$ 59231$

Source

<h:form id="form">
    <p:dataTable id="salesTable" var="sale" value="#{tableBean.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="Sales" />
            </p:row>

            <p:row>
                <p:column colspan="2" headerText="Sales Count" />
                <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>
            #{sale.manufacturer}
        </p:column>

        <p:column>
            #{sale.lastYearProfit}%
        </p:column>

        <p:column>
            #{sale.thisYearProfit}%
        </p:column>

        <p:column>
            #{sale.lastYearSale}$
        </p:column>

        <p:column>
            #{sale.thisYearSale}$
        </p:column>

        <p:columnGroup type="footer">
            <p:row>
                <p:column colspan="3" footerText="Totals:"
                                style="text-align:right"  />

                <p:column footerText="#{tableBean.lastYearTotal}$" />

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

        <f:facet name="footer">
            Use a bicycle instead of a car
        </f:facet>

    </p:dataTable>
</h:form>