EasyUI Forum
June 28, 2024, 08:52:31 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: delay on keypress event  (Read 5227 times)
rezzonico
Full Member
***
Posts: 186


View Profile
« on: February 26, 2016, 05:31:31 AM »

Hi all,

I have a datagrid with a combogrid field.
On this field and I have a "bind" on a "keypress" event:

Code:
odlEditor.target.combogrid('textbox').bind('keypress', function() {
   $.ajax({
      ...
   });
});

This works.
But to limit the execution of the ajax code I want to add a "delay" to the "keypress" event.
How is it possible ?

Thanks for any help.
Miche
« Last Edit: February 26, 2016, 05:56:10 AM by rezzonico » Logged
jarry
Administrator
Hero Member
*****
Posts: 2268


View Profile Email
« Reply #1 on: February 26, 2016, 09:06:16 AM »

The popular way to solve this issue is to use 'setTimeout' and 'clearTimeout' functions to delay an action on the 'keypress' event.
Code:
var timer = null;
.bind('keypress', function(){
if (timer){
clearTimeout(timer);
}
timer = setTimeout(function(){
$.ajax({...})
}, 400);
})
Logged
rezzonico
Full Member
***
Posts: 186


View Profile
« Reply #2 on: February 26, 2016, 09:42:06 AM »

It works !

Thanks a lot.
Miche
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!