Use FilterTextBox after a specific time

36 views
Skip to first unread message

Dominic Warzok

unread,
Aug 28, 2014, 7:39:55 AM8/28/14
to google-we...@googlegroups.com
Hi, 

in my webapp we have a very lagre collection. The user has the ability to filter these collection.

But if you tipe in one letter and start filtering it needs a lot of time. 

So I try to change the valueChangeHandler to only update the value in the box after 2 seconds when typing ended. 

This is my code:

  @Override
  public void onValueChange( ValueChangeEvent<String> event )
  {
    Timer t = new Timer()
    {
      @Override
      public void run()
      {
        addChangeHandler( new ChangeHandler()
        {
          @Override
          public void onChange( ChangeEvent event1 )
          {
            ValueChangeEvent.fire( TextBoxPSG.this, getValue() );
          }
        } );
      }
    };
    t.schedule( 15000 );
  }

But this doesn't work -.- 

Any suggestions ? 
Thanks in advance  

Tomek Kańka

unread,
Aug 31, 2014, 4:42:08 PM8/31/14
to google-we...@googlegroups.com

W dniu czwartek, 28 sierpnia 2014 13:39:55 UTC+2 użytkownik Dominic Warzok napisał:
Hi, 

in my webapp we have a very lagre collection. The user has the ability to filter these collection.
But if you tipe in one letter and start filtering it needs a lot of time. 
So I try to change the valueChangeHandler to only update the value in the box after 2 seconds when typing ended. 



AFAIR typing in TextBox doesn't triger ValueChangeEvent. Here is my solution:


    private Timer timer = null;
   
@UiHandler("filter")
   
public void onFilterKeyUp(KeyUpEvent event)
   
{
       
if (timer != null)
            timer
.cancel();
       
        timer
= new Timer()
       
{
           
public void run()
           
{
                getUiHandlers
().filter(filter.getText());
           
}
       
};
       
timer.schedule(500);

       
   
}




Reply all
Reply to author
Forward
0 new messages