aboutsummaryrefslogtreecommitdiffstats
path: root/demos/autocomplete/categories.html
blob: ff1c1510ed2b4d12afc3ec673e3082ec94e72ab3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!doctype html>
<html>
<head>
	<title>jQuery UI Autocomplete Custom Data Demo</title>
	<link type="text/css" href="../../themes/base/jquery.ui.all.css" rel="stylesheet" />
	<script type="text/javascript" src="../../jquery-1.4.2.js"></script>
	<script type="text/javascript" src="../../ui/jquery.ui.core.js"></script>
	<script type="text/javascript" src="../../ui/jquery.ui.widget.js"></script>
	<script type="text/javascript" src="../../ui/jquery.ui.position.js"></script>
	<script type="text/javascript" src="../../ui/jquery.ui.autocomplete.js"></script>
	<link type="text/css" href="../demos.css" rel="stylesheet" />
	<style type="text/css">
	
	</style>
	<script type="text/javascript">
	$(function() {
		var data = [
			{
				items: ["anders", "andreas", "antal"]
			},
			{
				category: "Products",
				items: ["annhhx10", "annk K12", "annttop C13"]
			},
			{
				category: "People",
				items: ["anders andersson", "andreas andersson", "andreas johnson"]
			}
		];
		
		$.widget("custom.catcomplete", $.ui.autocomplete, {
			_renderMenu: function( ul, items ) {
				var self = this;
				$.each( items, function( index, item ) {
					if ( item.category ) {
						ul.append( "<li class='category'>" + item.category + "</li>" );
					}
					$.each( item.items, function( index, item ) {
						self._renderItem( ul, {
							label: item
						});
					});
				});
			}
		});
		
		$('#search').catcomplete({
			source: function(request, response) {
				response(data);
			}
		});
	});
	</script>
</head>
<body>

<div class="demo">
	<label for="search">Search: </label>
	<input id="search" />
</div><!-- End demo -->

<div class="demo-description">
<p>
	A categorized search result. Currently just static data, will match anything you type.
</p>
</div><!-- End demo-description -->

</body>
</html>