Mirage LIVE PREVIEW

DataTable - Dynamic Columns

Columns of datatable can be created dynamically using the p:columns component.

Documentation
Available columns are "id","brand","year","color" and "price".
IDBRANDYEAR
fc108206Mercedes1980
662cb807Honda1981
a337317aAudi1995
abb63b20BMW1960
c0bc5cc4Ford2000
2be7baf0Renault2008
3c389556Jaguar1962
347357b9Ford2006
9b18463bRenault1983
e090dd05Volkswagen1982
Available columns are "id","brand","year","color" and "price".

<h:form id="form">    
    <h:panelGrid columns="3" style="margin:10px 0">
        <p:outputLabel for="template" value="Template:" style="font-weight:bold"/>
        <p:inputText id="template" value="#{dtColumnsView.columnTemplate}" size="50"/>
        <p:commandButton update="cars" action="#{dtColumnsView.updateColumns}" value="Update" process="@parent" icon="pi pi-refresh" oncomplete="PF('carsTable').clearFilters()"/>
    </h:panelGrid>

    <p:dataTable id="cars" var="car" value="#{dtColumnsView.cars}" widgetVar="carsTable" filteredValue="#{dtColumnsView.filteredCars}">                    
        <p:columns value="#{dtColumnsView.columns}" var="column" columnIndexVar="colIndex" sortBy="#{car[column.property]}" filterBy="#{car[column.property]}">
            <f:facet name="header">
                <h:outputText value="#{column.header}" />
            </f:facet>
            <h:outputText value="#{car[column.property]}" />
        </p:columns>
    </p:dataTable>
</h:form>