问题
I want to use inputtext to filter datagrid.
Some code like this:
<p:inputText value="#{bean.searchString}">
<p:ajax event="keyup" update="grid" />
</p:inputText>
<p:dataGrid var="item" value="#{bean.findItemsByName}" columns="9" layout="grid" rows="130" paginator="false" id="grid">
回答1:
There us no built in feature that allows datagrid filtering, but you can code your own.
Something like this (using google library):
Bean:
import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
//The full list
private List<String> names = new ArrayList<String>();
//The filtered list
private List<String> filterednames = new ArrayList<String>();
private String filterValue;
public void filterList() {
List<String> filteredList = Lists.newArrayList(Collections2.filter(
getNames(), Predicates.containsPattern(filterValue)));
setFilterednames(filteredList);
}
HXTML:
<p:inputText value="#{bean.filterValue}">
<p:ajax event="keyup" update="grid" listener="#{bean.filterList()}" />
</p:inputText>
<p:dataGrid var="name" value="#{bean.filterednames}" columns="9" layout="grid" rows="130" paginator="false" id="grid">
<h:outputText value="#{name}" />
</p:dataGrid>
来源:https://stackoverflow.com/questions/26749241/primefaces-datagrid-filter-by-inputtext