Richfaces column Filter: How to fire an event on intro key

帅比萌擦擦* 提交于 2019-12-04 07:13:56
Bozho

Unfortunately, there is no easy way to customize this functionality. There are options to make it more usable, though:

  • <a4j:queue requestDelay="1000" ignoreDupResponce="true" /> - place this in your <a4j:form> or <a4j:region> and your onkeyup requests will be delayed and grouped. See richfaces demo page:

    • Setting ignoreDupResponces to true reduces the count of DOM updates on typing inside the input. (in initial state count of updates is equals to count of requests)
    • Disabling the queue causes fully asynchronous updates. Note that updates could appear not only in direct order and as a result you could get wrong string.
    • Setting request delay to greater value reduces the requests count on fast typing. (More similar requests are combined in the result)
  • I'm currently using the following alternative:

    <rich:dataTable (..some attributes..)
        onkeypress="if (event.keyCode == 13) {document.getElementById('formId:tableId:j_id70fsp').blur(); return false;} else {return true;}"
        ><!-- disabling submit-on-enter -->
        <rich:column label="#{msg.name}" sortable="true" 
           filterBy="#{patient.profile.name}" filterEvent="onblur">
    </rich:dataTable>
    

    Where you have to see the generated id for j_id70fsp. It is not guaranteed that it will remain such forever, though.

    And the result is that the column is filtered on pressing the enter key, which is fairly usable.

zephid

Bozho is right, but instead of using getElementById I prefer using this script:

<rich:extendedDataTable onkeypress="
if (!event) { var event = window.event; }
if (event.keyCode == 13) {
    var targ;
    if (event.target) targ = event.target;
    else if (event.srcElement) targ = event.srcElement;
    if (targ.nodeType == 3) targ = targ.parentNode;
    if (targ) targ.blur();
    return false;
} else return true;">

It should work with FF, EI, Safari(the targ.nodeType == 3 thing).

function filterAllOnEnter(event)
{
   if(event.keyCode == 13)
   {
      jQuery(".rich-filter-input").blur();
      return false;
   }
   else
   {
      return true;
   }
}

<rich:dataTable onkeydown="filterAllOnEnter(event)" ... >

Works for me.

Angel_JAVA

With Richfaces 3.3.3, you must to quit the filter event (filterEvent="onblur") from each rich:column and then you will be able to filter only when enter key is pressed!

Israel Rios

Keep the onkeyup event and create a queue and associate it with the dataTable. It works but its undocumented:

<a4j:queue name="qFilter" ignoreDupResponses="true" size="1" requestDelay="600" sizeExceededBehavior="dropNext"/>

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