nbuytaert1 / apex-select2

Select lists in Oracle APEX as they should be
https://apex.oracle.com/pls/apex/f?p=64237:20
GNU General Public License v2.0
56 stars 18 forks source link

Arrange the drop down values in order of search term(Enhancement) #69

Closed brinal-dm closed 8 years ago

brinal-dm commented 8 years ago

Hi Nick,

Is there a way that I can list the option that matched with my search term first in drop down list or say rather arrange the values in drop down list in order that I enter in my search term?

For eg: search term = 'hnwe 34' and LOV consists of

  1. hnwe 34 stan for rl
  2. 123233 hnwe test
  3. hnwe 34 best

Then list the drop down value starting with hnwe 34 first and all the other options later on. So in this case the order will alphabetical based on search term like below: hnwe 34 best hnwe 34 stan for rl 123233 hnwe test

Is it something I can do easily or needs to update plugin?

brinal-dm commented 8 years ago

Hi Nick,

I have found the solution. I have added below piece to select2 item to sort as needed: sorter: function(results) { var query = $(''.select2-search_field'').val().toUpperCase(); query = query.replace(/ /g,'''') var c,d;
return results.sort(function(a, b) { c = a.text.replace(/ /g,'''').toUpperCase().indexOf(query); d = b.text.replace(/ /g,'''').toUpperCase().indexOf(query); if (c<0) c= c
-1; else c= c1; if(d<0) d=d-1; else d=d_1;

return c - d; });

}

This works for now. Thanks once again for integrating select2 plugin in apex.