Primefaces惰性数据表:放置我自己的过滤器而不是GlobalFilter [英] Primefaces lazy datatable: put my own filter instead of GlobalFilter
问题描述
我想在惰性数据表上添加一些额外的过滤器,但是这些字段不是基于我拥有的字段(实际上我的过滤器将是dateFrom和dateTo,而我只有一个字段 Date)。
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>
问题是,一旦我将id更改为除全局过滤器之外的其他内容,就不会检测到任何过滤器。我该怎么办?
The problem is that as soon as I change id into something else than global Filter, no filter is detected. How could I do?
推荐答案
最简单的方法是将两个(或更多)额外的过滤器字段绑定到 Map< String,String>
。例如,将一个名为 filters
的地图添加到您的bean:
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()"/>
现在,您唯一需要做的就是在 p:dataTable
,然后在事件过滤器中添加 filters
映射,就可以完成了。
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>
这篇关于Primefaces惰性数据表:放置我自己的过滤器而不是GlobalFilter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!