DataTable - Dynamic Columns Columns of datatable can be created dynamically using the p:columns component.
Available columns are "id","brand","year","color" and "price".
IDBRANDYEAR
867e2f09Fiat1993
d7e1dc6dFiat1967
e1efcbc8Fiat1964
a13e26b3Audi1979
b78834f0Renault1975
c1a6e7bcFord1996
d14aa58eRenault1989
525b90c7Fiat2007
988bea3bRenault2006
434a37baFord2003
<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" actionListener="#{dtColumnsView.updateColumns}" value="Update" process="@parent" icon="ui-icon-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>
                
PrimeTek, Copyright © 2017
All rights reserved.
Running PrimeFaces-6.1.4 on Mojarra-2.2.10.