I just tried to find documentation for catcomplete. I need manual for how to use _renderItem. I have found this http://jqueryui.com/autocomplete/#categories but seems there is no mention about that only just example for _renderMenu
    _renderMenu: function( ul, items ) {
        var that = this,
            currentCategory = "";
        $.each( items, function( index, item ) {
            if ( item.category != currentCategory ) {
                ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
                currentCategory = item.category;
            }
            that._renderItemData( ul, item );
        });
    }
catcomplete is just an example and unfortunately not a part of jQuery UI, so there is no documentation for _renderItem or renderMenu.  Think of this as a part of the jQuery source code.  However the effect can very easily be reproduced from the source code.
To use catcomplete, we need to simply ensure that both a label and category value are passed to catcomplete as demonstrated:
var data = [
    { label: "anders", category: "" },
    { label: "andreas", category: "" },
    { label: "antal", category: "" },
    { label: "annhhx10", category: "Products"},
    { label: "annk K12", category: "Products" },
    { label: "annttop C13", category: "Products" },
    { label: "anders andersson", category: "People" },
    { label: "andreas andersson", category: "People" },
    { label: "andreas johnson", category: "People" }
];
Items with a blank string as a category will be not be put into a category and left as with the standard autocomplete. Those given a category will be sub-menued under that category.
Fiddle here (of the jQuery example)
To add a class to each item you can simply append .addClass(item.category) to the end of the last line of code in the catcomplete widget:
that._renderItemData( ul, item ).addClass(item.category);
updated fiddle here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With