user1820622
user1820622

Reputation: 85

Primefaces Datatable search for filter

The default setting updates the table on each keystroke in the filter field.I want to display the result list only when the user enters something and presses enter.

Upvotes: 4

Views: 5916

Answers (4)

user3655551
user3655551

Reputation: 111

You can use appropriate option of column now. The simplest example of data column is:

p:column filterEvent="enter"

Upvotes: 0

Erick Alves
Erick Alves

Reputation: 354

It's important to emphasize that filterEvent is an attribute of dataTable tag, in this e.g. javascript workaround has showed in the column tag, but this is not work well. 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 e.g below:

<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.

Upvotes: 1

kolossus
kolossus

Reputation: 20691

You haven't stated your version, but you can use the enter event on filterEvent since PF 3.2. Earlier version , you can use this javascript workaround

Upvotes: 2

Daniel
Daniel

Reputation: 37061

for global filter you can use 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>  

Upvotes: 2

Related Questions