Advertisement
ivana_andreevska

Autocomplete

Dec 23rd, 2021
1,122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.89 KB | None | 0 0
  1. $(document).ready(function (){
  2.     var items=[
  3.         {label:"Product1" , category:"Laptop"},
  4.         {label:"Product2" , category:"Laptop"},
  5.         {label:"Product3" , category:"Laptop"},
  6.         {label:"Product4" , category:"Tastatura"},
  7.         {label:"Product5" , category:"Tastatura"},
  8.         {label:"Product6" , category:"Tastatura"},
  9.         {label:"Product7" , category:"Zvucnici"},
  10.         {label:"Product8" , category:"Zvucni"},
  11.     ]
  12.     $("#autocomplete").autocomplete({
  13.     source:items
  14.     }).autocomplete("instance")._renderMenu=function( ul, items ) {
  15.         var currentCategory=""
  16.         $.each( items, function( index, item ) {
  17.         if(item.category!=currentCategory)
  18.         {
  19.             ul.append("<li><b>"+item.category+"</b></li>")
  20.             currentCategory=item.category;
  21.         }
  22.         ul.append("<li>"+item.label+"</li>")
  23.  
  24.         });
  25.     }
  26. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement