Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Auto complete append link at the bottom

I am using jQuery auto-complete plugin in my web project. I want to show 3 element and after that i want to append 'see all results' link to the bottom. Jquery Autocomplete

I tried with following code.

$( ".grid-search-box" ).autocomplete({
      minLength: 0,
      source: temp,
    focus: function( event, ui ) {
       $( ".grid-search-box" ).val( ui.item.value );
       return false;
     },
     select: function( event, ui ) {
        $( ".grid-search-box" ).val( ui.item.value );
          return false;
             }
    }).data( "autocomplete" )._renderItem = function( ul, item ) 
         {
        return $( "<li></li>" )
           .data( "item.autocomplete", item )
           .append( "<a><span class='" + item.status + "'></span>" + item.value + "</a>" )
        .appendTo( ul );
                        };

Can anybody suggest me, how to solve it.

like image 825
Ashwin Preetham Lobo Avatar asked Sep 18 '12 14:09

Ashwin Preetham Lobo


1 Answers

Here is the demo,

http://jsfiddle.net/muthkum/vqwBP/105/

I hope you will figure out how to implement.

Update: I managed to update your code,

$( ".grid-search-box" ).autocomplete({
      minLength: 0,
      source: function(request, response) {
        var results = $.ui.autocomplete.filter(temp, request.term);

        response(results.slice(0, 3)); //show 3 items.
    },
    open: function(event, ui) {
        $('.ui-autocomplete').append('<li><a href="javascript:alert(\'redirecting...\')">See All Result</a></li>'); //See all results
         },
    focus: function( event, ui ) {
       $( ".grid-search-box" ).val( ui.item.value );
       return false;
     },
     select: function( event, ui ) {
        $( ".grid-search-box" ).val( ui.item.value );
          return false;
    }
}).data( "autocomplete" )._renderItem = function( ul, item ) {
        return $( "<li></li>" )
           .data( "item.autocomplete", item )
           .append( "<a><span class='" + item.status + "'></span>" + item.value + "</a>" )
        .appendTo( ul );
};

Demo: http://jsfiddle.net/muthkum/vqwBP/106/

like image 125
Muthu Kumaran Avatar answered Nov 01 '22 10:11

Muthu Kumaran