Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primefaces p:dataTable filter not working with p:columns

Our project uses JSF 2.2 primeface 5.1. I use the following code to show the datatable in my JSF page, I added <f:facet name="filter"> for the dynamic filter based on the type of dynamic column. But when I typed in the criteria on the head of each column or select drop down list, the datatable is not filtering.

If I remove the <f:facet name="filter"> section. Though the filter type will not be dynamically changing(it will always be input text), but the filtering works, datatable will be filtered based on the criteria typed in. Any idea will be much appreciated.

<p:dataTable id="myTable" var="model" value="#{myBackingBean.dynaModels}" widgetVar="tableWidget" editable="true" styleClass="ui-dyna-table" 
         rows="15" paginator="true" resizableColumns="true" tableStyle="width:auto" emptyMessage=""> 
<p:columns value="#{myBackingBean.myProperties}" var="myProperty" columnIndexVar="colIndex" styleClass="ui-editable-column" width="50px" filterBy="#{model.dyanModel[myProperty.propertyKey].value}" sortBy="#{model.dyanModel[myProperty.propertyKey].value}">
    <f:facet name="header" >
        <h:outputText value="#{myProperty.descr}" />                                     
    </f:facet>
    <f:facet name="filter" >
        <p:selectOneMenu rendered="#{myProperty.componentType.value eq 'S1'}" style="width:100px" onchange="PF('tableWidget').filter()" >
            <f:selectItem itemValue="" noSelectionOption="true"/>
            <f:selectItems value="#{myProperty.lov}" />
        </p:selectOneMenu>
        <p:inputText rendered="#{myProperty.componentType.value eq 'TXT'}" style="width:80px" onchange="PF('tableWidget').filter()" />
        <p:calendar rendered="#{myProperty.componentType.value eq 'DT'}" showOn="button" pattern="dd-MMM-yyyy" onchange="PF('tableWidget').filter()" >                              
        </p:calendar>
    </f:facet>
    <h:outputText value="#{model.dyanModel[myProperty.propertyKey].value}"  />
</p:columns>

like image 350
Kuku Avatar asked Sep 28 '22 21:09

Kuku


1 Answers

After some search I found this is a known prime faces bug. The filter inside dynamic p:columns not working. I try to change my jsf with the following work around and it works.

<c:forEach ...>
   <p:column>
   </p:column>
</c:forEach>

instead of 

<p:columns>
</p:columns>
like image 176
Kuku Avatar answered Oct 05 '22 07:10

Kuku