DataTable - ColumnToggler

ColumnToggler is a helper component of datatable to toggle the visibility of columns.

List of Cars
IdYearBrandColorPrice
a725217a1966VolvoBlack$72,405.00
da61fbdb2000RenaultBlack$81,760.00
00e3d2d91963AudiBlack$56,890.00
90596a702008FordSilver$83,495.00
ce9e17511985BMWMaroon$57,554.00
1b3f554c1982HondaWhite$2,689.00
2ff53d0e1990JaguarYellow$53,004.00
7c15fb731999JaguarYellow$80,026.00
fc9b1ebc1992AudiYellow$29,937.00
222879aa1987FiatRed$76,091.00
<p:dataTable id="cars" var="car" value="#{dtBasicView.cars}">
    <f:facet name="header">
        List of Cars

        <p:commandButton id="toggler" type="button" value="Columns" style="float:right" icon="ui-icon-calculator" />
        <p:columnToggler datasource="cars" trigger="toggler" />
    </f:facet>

    <p:column headerText="Id">
        <h:outputText value="#{car.id}" />
    </p:column>

    <p:column headerText="Year">
        <h:outputText value="#{car.year}" />
    </p:column>

    <p:column headerText="Brand">
        <h:outputText value="#{car.brand}" />
    </p:column>

    <p:column headerText="Color">
        <h:outputText value="#{car.color}" />
    </p:column>

    <p:column headerText="Price">
        <h:outputText value="#{car.price}">
            <f:convertNumber type="currency" currencySymbol="$" />
        </h:outputText>
    </p:column>
</p:dataTable>