Mirage LIVE PREVIEW

DataTable - ColumnToggler

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

Documentation
List of Cars
IdYearBrandColorPrice
1969f0e81965FiatRed$68,665.00
2b1f6b591980VolkswagenBlue$99,940.00
02cf37881977BMWBlue$83,661.00
b4cd57991984VolvoGreen$53,320.00
c7320ecb1992VolvoYellow$53,784.00
24596e851968FiatOrange$6,507.00
9f0a82e11961BMWSilver$9,947.00
02dbeed71974AudiGreen$32,689.00
dbf03fbb1997VolkswagenOrange$99,751.00
8f7843651960HondaRed$96,112.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>