DataTable - ColumnToggler

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

List of Cars
IdYearBrandColorPrice
144af8c31986MercedesSilver$85,874.00
0e6efe991997HondaMaroon$28,794.00
3903b19e1998RenaultBlue$61,052.00
4052b1c51968JaguarOrange$70,696.00
9ca7f2161960MercedesSilver$85,984.00
d55fd3d12006FordYellow$14,627.00
e0cb4bbc2006JaguarSilver$23,177.00
a48f7aa81983HondaGreen$23,849.00
1de3c5822009FiatWhite$47,337.00
4501fe842008AudiBrown$88,813.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>