jquery-ui/demos/autocomplete/categories.html

72 lines
1.8 KiB
HTML
Raw Normal View History

2010-03-17 23:42:32 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
2010-09-10 02:24:52 +00:00
<meta charset="utf-8">
2010-09-10 02:33:09 +00:00
<title>jQuery UI Autocomplete - Categories</title>
2010-09-10 02:24:52 +00:00
<link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
2011-11-22 13:54:02 +00:00
<script src="../../jquery-1.7.1.js"></script>
2010-09-10 02:24:52 +00:00
<script src="../../ui/jquery.ui.core.js"></script>
<script src="../../ui/jquery.ui.widget.js"></script>
<script src="../../ui/jquery.ui.position.js"></script>
<script src="../../ui/jquery.ui.autocomplete.js"></script>
<link rel="stylesheet" href="../demos.css">
<style>
2010-03-17 23:42:32 +00:00
.ui-autocomplete-category {
2010-09-10 02:24:52 +00:00
font-weight: bold;
padding: .2em .4em;
margin: .8em 0 .2em;
line-height: 1.5;
2010-03-17 23:42:32 +00:00
}
</style>
2010-09-10 02:24:52 +00:00
<script>
$.widget( "custom.catcomplete", $.ui.autocomplete, {
2010-03-17 23:42:32 +00:00
_renderMenu: function( ul, items ) {
var self = this,
currentCategory = "";
$.each( items, function( index, item ) {
if ( item.category != currentCategory ) {
ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
currentCategory = item.category;
}
self._renderItem( ul, item );
});
}
});
</script>
2010-09-10 02:24:52 +00:00
<script>
2010-03-17 23:42:32 +00:00
$(function() {
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" }
];
2010-09-10 02:24:52 +00:00
$( "#search" ).catcomplete({
2010-03-17 23:42:32 +00:00
delay: 0,
source: data
});
});
</script>
</head>
<body>
<div class="demo">
<label for="search">Search: </label>
<input id="search" />
</div><!-- End demo -->
2010-09-10 02:24:52 +00:00
2010-03-17 23:42:32 +00:00
<div class="demo-description">
2010-09-10 02:24:52 +00:00
<p>A categorized search result. Try typing "a" or "n".</p>
2010-03-17 23:42:32 +00:00
</div><!-- End demo-description -->
</body>
</html>