DataTable - ColumnToggler ColumnToggler is a helper component of datatable to toggle the visibility of columns.
List of Cars
IdYearBrandColorPrice
e77b66e91962JaguarMaroon$35,667.00
97bd19291990VolvoBlue$82,313.00
e8e46dfe1964HondaMaroon$72,152.00
199126d91981VolvoMaroon$63,865.00
91282d4e2005JaguarSilver$12,666.00
dec2d4041972FiatOrange$96,950.00
93cf011d1968FordBrown$72,642.00
06fff0f11974MercedesRed$88,948.00
3f4f3f971982FiatOrange$32,097.00
ab3363ec1982VolvoYellow$98,200.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.