bassjobsen / Bootstrap-3-Typeahead

The Typeahead plugin from Twitter's Bootstrap 2 ready to use with Bootstrap 3 and Bootstrap 4
1.68k stars 1.33k forks source link

How to sort the suggestions ? #371

Closed chankruze closed 5 years ago

chankruze commented 5 years ago

when i write first letter it shows all the data which contains that particular letter and it's also case sensitive all irrelevant suggestions. I am trying to sort the suggestion with in-built sorter function. My code snippet is given below,

var autoComplete = $('#repository').typeahead({ 
        autoSelect: true,
        sorter:function(repoNames, b) { 

        //get input text
        var InputString= $("#repository").val();

        //move exact matches to top
        if(InputString == a.value){ return -1;}
        if(InputString == b.value){return 1;}

        //close match without case matching
        if(InputString.toLowerCase() == a.value.toLowerCase()){ return -1;}
        if(InputString.toLowerCase()== b.value.toLowerCase()){return 1;} 

        if( (InputString != a.value) && (InputString != b.value)){

             if (a.value < b.value) {
                return -1;
             }
             else if (a.value > b.value) {
                return 1;
             }
             else return 0;
        }
     },
        afterSelect: function() {
            $("#get-stats-button").click();
        }
     });

Now the thing i can't understand is what the heck the functions parameters will be ? what is a and b ?