使用 primefaces 的数据表不过滤
Datatable using primefaces doesnt filter
我的数据表显示结果,但不按协议过滤,使用 JSF 有效,但 promefaces 不显示任何内容,我的代码是:
<p:dataTable value="#{registroBean.listarRegistros()}"
var="registro"
widgetVar="registroTable"
id="tabelaRegistro"
class="table table-striped table-hover"
rendered="#{not empty registroBean.listarRegistros()}">
<f:facet name="header">
<p:outputPanel>
<p:inputText id="globalFilter" onkeyup="PF('registroTable').filter()" style="width:100%" placeholder="Digite o protocolo" />
</p:outputPanel>
</f:facet>
<p:column filterBy="{#registro.protocolo}">
<f:facet name="header">Protocolo</f:facet>
<h:outputText value="#{registro.protocolo}" />
</p:column>
</p:dataTable>
当我输入搜索时 return:
没有找到记录。
我做错了什么?
您应该为托管 Bean 中的筛选结果创建一个空的 ArrayList,并将其设置到您的 DataTable,如下所示:
<p:dataTable value="#{registroBean.listarRegistros()}"
filteredValue="#{registroBean.filtredRegistro}"
var="registro"
widgetVar="registroTable"
id="tabelaRegistro"
class="table table-striped table-hover"
rendered="#{not emptyregistroBean.listarRegistros()}">
并在您的 RegistroBean
中使用 getter 和 setter 添加此属性
private ArrayList<YourClass> filtredRegistro;
//Getter And Setter
public ArrayList<YourClass> getfiltredRegistro(){
return this.filtredRegistro;
}
public void setfiltredRegistro(filtredRegistro){
this.filtredRegistro=filtredRegistro;
}
我的数据表显示结果,但不按协议过滤,使用 JSF 有效,但 promefaces 不显示任何内容,我的代码是:
<p:dataTable value="#{registroBean.listarRegistros()}"
var="registro"
widgetVar="registroTable"
id="tabelaRegistro"
class="table table-striped table-hover"
rendered="#{not empty registroBean.listarRegistros()}">
<f:facet name="header">
<p:outputPanel>
<p:inputText id="globalFilter" onkeyup="PF('registroTable').filter()" style="width:100%" placeholder="Digite o protocolo" />
</p:outputPanel>
</f:facet>
<p:column filterBy="{#registro.protocolo}">
<f:facet name="header">Protocolo</f:facet>
<h:outputText value="#{registro.protocolo}" />
</p:column>
</p:dataTable>
当我输入搜索时 return: 没有找到记录。
我做错了什么?
您应该为托管 Bean 中的筛选结果创建一个空的 ArrayList,并将其设置到您的 DataTable,如下所示:
<p:dataTable value="#{registroBean.listarRegistros()}"
filteredValue="#{registroBean.filtredRegistro}"
var="registro"
widgetVar="registroTable"
id="tabelaRegistro"
class="table table-striped table-hover"
rendered="#{not emptyregistroBean.listarRegistros()}">
并在您的 RegistroBean
中使用 getter 和 setter 添加此属性private ArrayList<YourClass> filtredRegistro;
//Getter And Setter
public ArrayList<YourClass> getfiltredRegistro(){
return this.filtredRegistro;
}
public void setfiltredRegistro(filtredRegistro){
this.filtredRegistro=filtredRegistro;
}