EasyUI Forum
June 22, 2024, 03:35:10 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: Combobox insensitive casse and contains search options  (Read 22861 times)
jr
Newbie
*
Posts: 3


View Profile Email
« on: February 22, 2012, 08:26:57 AM »

Hi,

I need to allow user make insentive and contains search unto combobox.

For example, if my options are :

  • Apple
  • Banana
  • Pineapple
  • Tomato

If used enter "apple", i need that both "Apple" and "Pineapple" appear in filter results.

It would be also very nice if i can highlight filter part on result.

How to achieve this ?

Regards.

PS : Sorry for my english, i'm french speaker.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: February 23, 2012, 12:31:28 AM »

Try override combobox filter fucntion:
Code:
$.fn.combobox.defaults.filter = function(q,row){
var opts = $(this).combobox('options');
return row[opts.textField].indexOf(q) >= 0;
};
Logged
jr
Newbie
*
Posts: 3


View Profile Email
« Reply #2 on: February 23, 2012, 03:03:05 AM »

Hi,

Thanks a lot.

It puts me on the way.

1- To handle insensitive casse, just override default filter like that (adding toUpperCase() or toLowerCase() and "== 0") :
Code:
$.fn.combobox.defaults.filter = function(q,row){
       var opts = $(this).combobox('options');
       return row[opts.textField].toUpperCase().indexOf(q.toUpperCase()) == 0;
};

2- To search inside the string like i wanted, just put ">= 0" like stworthy suggested
Code:
$.fn.combobox.defaults.filter = function(q,row){
      var opts = $(this).combobox('options');
      return row[opts.textField].toUpperCase().indexOf(q.toUpperCase()) >= 0;
};

For newbies like me, place these code outside of the jQuery $(document).ready scope, otherwise it don't works.

Thanks again, it works perfectly

Regards.
Logged
sky_proj
Newbie
*
Posts: 24


View Profile
« Reply #3 on: April 11, 2013, 10:06:56 PM »

this function ok :
$.fn.combobox.defaults.filter = function(q,row){
       var opts = $(this).combobox('options');
       return row[opts.textField].toUpperCase().indexOf(q.toUpperCase()) == 0;
};

if my data:
Apple
Angle
Antenna

when i enter :
'Apple' will show 'Apple' and selected (highlight yellow show)

but when i enter :
'apple' will show Apple but nothing selected (highlight yellow not show) => this is my question how to make selected (highlight yellow show on 'Apple')

thank's
















Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #4 on: April 12, 2013, 12:21:34 AM »

To customize how to find and select a specified item when querying items, please override the $.fn.combobox.defaults.keyHandler.query.
Code:
<script>
(function($){
var oldQuery = $.fn.combobox.defaults.keyHandler.query;
$.fn.combobox.defaults.keyHandler.query = function(q){
oldQuery.call(this, q);
var opts = $(this).combobox('options');
if (opts.mode == 'local'){
var data = $(this).combobox('getData');
for(var i=0; i<data.length; i++){
if (data[i][opts.textField].toLowerCase() == q.toLowerCase()){
$(this).combobox('setValue', data[i][opts.valueField]);
return;
}
}
}
};
})(jQuery);
</script>
Logged
sky_proj
Newbie
*
Posts: 24


View Profile
« Reply #5 on: April 12, 2013, 08:22:39 PM »

thanx's stworthy... that function it work for me!!
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!