DataTable - ColumnToggler

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

List of Cars
IdYearBrandColorPrice
6c2a94c31977FordYellow$50,590.00
75fbb9801968VolvoOrange$16,055.00
128b70791973RenaultGreen$20,774.00
aed5c2c11963RenaultRed$6,556.00
961950c71966VolvoSilver$19,230.00
bda9aa9b1992FiatBlue$92,868.00
03cdf19c1977VolvoBrown$33,150.00
f626a6771984HondaBlue$35,728.00
1902227c2008FordMaroon$61,142.00
ffe83ef41999MercedesBrown$50,673.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>