简体   繁体   English

Primefaces Datatable搜索过滤器

[英]Primefaces Datatable search for filter

默认设置更新过滤器字段中每次击键时的表。我想仅在用户输入内容并按回车键时显示结果列表。

for global filter you can use event.keyCode == 13 对于全局过滤器,您可以使用event.keyCode == 13

like this 像这样

<f:facet name="header">  
    <p:outputPanel>  
       <h:outputText value="Search all fields:" />  
       <p:inputText id="globalFilter" onkeyup="if (event.keyCode == 13) { 
           carsTable.filter(); }" style="width:150px" />  
    </p:outputPanel>  
</f:facet>  

You haven't stated your version, but you can use the enter event on filterEvent since PF 3.2. 您尚未说明您的版本,但您可以在PF 3.2之后使用filterEvent上的enter事件。 Earlier version , you can use this javascript workaround 早期版本,您可以使用此JavaScript解决方法

It's important to emphasize that filterEvent is an attribute of dataTable tag, in this eg javascript workaround has showed in the column tag, but this is not work well. 重要的是要强调filterEvent是dataTable标记的一个属性,例如javascript变通方法已在列标记中显示,但这不能很好地工作。 You can use like this: 你可以像这样使用:

<p:dataTable id="companyTable" 
     value="#{fooManager.foo}" var="foo"
     filterEvent="enter">

    <p:column filterBy="#{foo.name}" >
        <h:outputText value="#{foo.name}" />
    </p:column>

</p:dataTable>

Or you may use with filterEvent="Keyup" which is the default value of this attribute and filterDelay defined in 1000 milliseconds before sending an ajax filter query (Default is 300 miliseconds), like the eg below: 或者您可以使用filterEvent =“Keyup”,这是此属性的默认值,并且在发送ajax过滤器查询(默认值为300毫秒)之前,在1000毫秒内定义filterDelay,如下所示:

<p:dataTable id="companyTable" 
     value="#{fooManager.foo}" var="foo"
     filterEvent="keyup"
     filterDelay="1000">

    <p:column filterBy="#{foo.name}" >
        <h:outputText value="#{foo.name}" />
    </p:column>

</p:dataTable>

I hope help you. 我希望能帮助你。

You can use appropriate option of column now. 您现在可以使用适当的列选项。 The simplest example of data column is: 最简单的数据列示例是:

p:column filterEvent="enter"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM