DataTable - ColumnToggler

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

List of Cars
IdYearBrandColorPrice
4c47d1751962HondaBrown$90,246.00
b8a6de491996AudiWhite$22,513.00
c32650d61971JaguarMaroon$53,055.00
019b4b9d1968BMWBlack$43,918.00
f19de55d1978BMWBrown$49,565.00
580b21251986FordSilver$21,108.00
e87d8ccf2001VolvoOrange$48,790.00
0979ec961993HondaWhite$79,106.00
fa10a9d31974JaguarOrange$91,114.00
c546a2681995FordMaroon$46,187.00
<style type="text/css">
    .ui-datatable-header {
        height: 50px
    }
</style>


<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="pi pi-align-justify" />
        <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>