DataTable - ColumnToggler

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

List of Cars
IdYearBrandColorPrice
550e6fe71996JaguarMaroon$79,995.00
18b796551969MercedesMaroon$98,830.00
204f8e821965VolkswagenSilver$83,902.00
f9f8cd1c1969FiatBrown$7,415.00
4b71ebf41970FordSilver$15,353.00
eedfbf271984FiatSilver$55,244.00
3a2e54561960BMWBrown$21,400.00
cfb19e052001FordGreen$49,022.00
43c3f5ac1992VolkswagenWhite$61,663.00
528d89fd1996BMWYellow$1,308.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>