primefaces datagrid filter by inputtext

北战南征 提交于 2021-01-28 01:54:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!