DataTable - ColumnToggler

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

List of Cars
IdYearBrandColorPrice
c2c12cb21976HondaRed$3,171.00
1fa8c03d1983VolkswagenSilver$71,546.00
ee509d4e1994MercedesBlue$97,975.00
a7adaf351969MercedesSilver$85,967.00
255f094b1968FordBlue$55,379.00
ca79e3ca1990VolvoYellow$44,478.00
88f26a971989RenaultWhite$76,331.00
c09adc051969VolkswagenGreen$53,027.00
e31def1b1978AudiMaroon$42,462.00
ee92e6591996HondaYellow$99,500.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>