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 );
});
}
catcompleteis just an example and unfortunately not a part of jQuery UI, so there is no documentation for_renderItemorrenderMenu. 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
labelandcategoryvalue are passed tocatcompleteas demonstrated: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 thecatcompletewidget:updated fiddle here