DataTable - ColumnToggler

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

List of Cars
IdYearBrandColorPrice
b7dd312b2005VolkswagenRed$63,888.00
14db1ee21965JaguarMaroon$6,456.00
26e3da581982FiatWhite$55,834.00
39f240fe1988HondaOrange$37,056.00
8651efef1977FiatBlack$57,994.00
dbde97561993FiatMaroon$73,913.00
a64d0a321960RenaultMaroon$96,726.00
5defcace1986BMWSilver$65,322.00
2cf1d5921991AudiRed$16,081.00
4b66c3ce1963VolvoGreen$49,314.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>