DataTable - ColumnToggler ColumnToggler is a helper component of datatable to toggle the visibility of columns.
List of Cars
IdYearBrandColorPrice
8818de242005MercedesRed$89,304.00
8dd6608f1976BMWGreen$81,548.00
de85e51a1970RenaultBrown$18,682.00
1373cd542001VolvoYellow$50,313.00
9fe3acd91961MercedesMaroon$34,297.00
0985913a1963BMWBrown$82,039.00
37bc3ef81983AudiBrown$31,195.00
4137558e1992FiatBlue$97,217.00
2bc3faf11966VolkswagenOrange$73,145.00
32be19841963VolkswagenBrown$89,378.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.