EasyUI Forum
May 14, 2024, 08:57:00 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: combobox filter remote  (Read 9294 times)
lomonmic
Newbie
*
Posts: 12


View Profile
« on: April 11, 2017, 10:24:17 AM »

Good evening, I apologize for my poor English, use a translator.
I defined a combobox with a remote datasource, but when I type something in the input box called the server to each character by slowing down the operation.
You can call the server unless I have written at least 3-4 characters?

my code attached.

Thank you.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: April 11, 2017, 05:30:12 PM »

You can override the 'loader' function to wait the inputing characters until its length equals or greater than 3. Please refer to the code below:
Code:
$('#cc').combobox({
mode: 'remote',
url: 'test.php',
loader: function(param,succ,error){
var opts = $(this).combobox('options');
if (!opts.url){return false}
if (param.q != undefined){
var q = param.q || '';
if (q.length < 3){return false}
}
$.ajax({
type: opts.method,
url: opts.url,
data: param,
dataType: 'json',
success: function(data){
success(data);
},
error: function(){
error.apply(this, arguments);
}
});

}
})
Logged
lomonmic
Newbie
*
Posts: 12


View Profile
« Reply #2 on: April 11, 2017, 09:11:37 PM »

Thanks, now I try and let you know.
Michele.
Logged
lomonmic
Newbie
*
Posts: 12


View Profile
« Reply #3 on: April 12, 2017, 01:15:01 AM »

Good morning, I tried to insert the recommended code, but still dominates the event: doFilter default. see Attachment.

Thank you.
Michele.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #4 on: April 12, 2017, 11:46:45 PM »

The 'loader' function must be moved to the 'options'. But it seams that you don't need this function. If you want to do the filter after selecting an item from the combobox, please try this code:
Code:
field:'comune_azienda',
type:'combobox',
options:{
editable:true,
url:'getComuni.php',
reversed:true,
onChange:function(value){
if (value == ''){
dg.datagrid('removeFilterRule', 'comune_azienda');
} else {
dg.datagrid('addFilterRule', {
field: 'comune_azienda',
op: 'equal',
value: value
});
}
dg.datagrid('doFilter');
}
}
Logged
lomonmic
Newbie
*
Posts: 12


View Profile
« Reply #5 on: April 13, 2017, 10:16:10 AM »

Thank you.
This time it works fine.

Greetings.
Lo Monaco Michele.
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!