DataTable - ColumnToggler ColumnToggler is a helper component of datatable to toggle the visibility of columns.
List of Cars
IdYearBrandColorPrice
bf4938bf1979JaguarGreen$94,079.00
112897cc1960FordBlue$39,435.00
7926d4bb1978VolvoYellow$25,143.00
de5650781984HondaRed$77,132.00
e0e1b3fa2002FordRed$84,025.00
85d587192002MercedesYellow$60,789.00
6fcdf6901960RenaultGreen$12,244.00
b87284b52004BMWBrown$98,319.00
4a80fecd1989BMWSilver$2,516.00
d3d7974a1994RenaultBrown$73,329.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>
                
PrimeTek, Copyright © 2017
All rights reserved.
Running PrimeFaces-6.2-SNAPSHOT on Mojarra-2.3.2.