DataTable - ColumnToggler

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

List of Cars
IdYearBrandColorPrice
3ab1cdfa1994MercedesWhite$23,449.00
738631571961BMWRed$55,249.00
30deb9402007VolvoBrown$60,517.00
4e901fe71962MercedesRed$31,271.00
26d906501982BMWBrown$60,291.00
9d5805581970FordSilver$97,207.00
1476e5d71963HondaRed$46,108.00
94682d542003FiatOrange$44,908.00
733295be1969FordBlue$95,243.00
70aee99b1985HondaSilver$58,163.00
<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="ui-icon-calculator" />
        <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>