问题
I d like to add some extra filters on my Lazy Data Table but these fields are not based on the fields I have (actually my filter would be dateFrom and dateTo and I only have a field "Date").
I'd like to have two extra filter fields on the top of my datatable instead of a global filter:
<f:facet name="header">
<p:outputPanel>
<p:inputText id="globalFilterOther" onkeyup="PF('myTable').filter()" style="display:inlineblock;"/>
<p:inputText id="globalFilterAnOtherFilter" onkeyup="PF('myTable').filter()" style="display:inlineblock;"/>
</p:outputPanel>
</f:facet>
The problem is that as soon as I change id into something else than global Filter, no filter is detected. How could I do?
回答1:
The easiest way is binding the two (or more) extra filter fields to a Map<String,String>
. For example add a map called filters
to your bean:
private Map<String,String> filters = new HashMap<>();
// Include getter and setter
... and bind the filters to properties of the map:
<p:inputText value="#{myBean['field']}"
onkeyup="PF('myTable').filter()"/>
<p:inputText value="#{myBean['otherField']}"
onkeyup="PF('myTable').filter()"/>
Now, the only thing you need to do is adding a filter listener to the p:dataTable
, and there add the filters
map to the event filters and you are done.
Bean:
public void onFilter(FilterEvent event){
event.getFilters().putAll(filters);
}
XHTML:
<p:dataTable ...>
<p:ajax event="filter" listener="#{myBean.onFilter}"/>
</p:dataTable>
来源:https://stackoverflow.com/questions/49304057/primefaces-lazy-datatable-put-my-own-filter-instead-of-globalfilter