jquery-ui/demos/autocomplete/categories.html

68 lines
1.8 KiB
HTML
Raw Normal View History

2012-09-10 15:33:46 +00:00
<!doctype html>
2010-03-17 23:42:32 +00:00
<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">
2012-09-21 01:41:47 +00:00
<script src="../../jquery-1.8.2.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.menu.js"></script>
2010-09-10 02:24:52 +00:00
<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 that = this,
2010-03-17 23:42:32 +00:00
currentCategory = "";
$.each( items, function( index, item ) {
if ( item.category != currentCategory ) {
ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
currentCategory = item.category;
}
2012-09-10 15:33:46 +00:00
that._renderItemData( ul, item );
2010-03-17 23:42:32 +00:00
});
}
});
</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" }
];
2011-05-27 12:32:48 +00:00
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>
2012-09-10 15:33:46 +00:00
<label for="search">Search: </label>
<input id="search">
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>
2012-09-10 15:33:46 +00:00
</div>
2010-03-17 23:42:32 +00:00
</body>
</html>