forked from jquery/jquery-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautocomplete.html
More file actions
88 lines (81 loc) · 2.26 KB
/
autocomplete.html
File metadata and controls
88 lines (81 loc) · 2.26 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Grid: Autocomplete</title>
<link rel="stylesheet" href="../themes/base/jquery.ui.all.css">
<link rel="stylesheet" href="../demos/demos.css">
<script src="../jquery-1.7.2.js"></script>
<script src="../external/jquery.tmpl.js"></script>
<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>
<script src="../ui/jquery.ui.autocomplete.js"></script>
<script src="../ui/jquery.ui.observable.js"></script>
<script src="../ui/jquery.ui.dataview.js"></script>
<script src="../ui/jquery.ui.grid.js"></script>
<script>
$(function() {
var cities = $.ui.dataview({
source: function( request, response ) {
$.ajax({
url: "http://ws.geonames.org/searchJSON",
dataType: "jsonp",
data: {
featureClass: "P",
style: "full",
maxRows: 12,
name_startsWith: request.filter.term
},
success: function( data ) {
var result = $.map( data.geonames, function( item ) {
return $.extend({
label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
value: item.name
}, item );
});
response( result, data.totalResultsCount );
}
});
}
});
$("#city").autocomplete({
minLength: 3,
source: function( request, response ) {
cities.option( "filter", request ).refresh( function() {
response( cities.result );
});
}
});
// secondary view
// TODO the table is empty, so let's create it from scratch here
var grid = $( "#table1" ).grid({
source: cities.result,
columns: [
{ property: "name", label: "Name" },
{ property: "adminName1", label: "Area" },
{ property: "adminName2", label: "Province" },
{ property: "population", label: "Population" },
{ property: "countryName", label: "Country" }
]
});
});
</script>
</head>
<body>
<h1>Autocomplete with custom dataview and secondary grid view</h1>
<p>features: filtering</p>
<form>
<label for="city">City</label><input id="city">
</form>
<div style="width:70em;">
<table id="table1">
<thead>
</thead>
<tbody>
</tbody>
</table>
</div>
</body>
</html>