-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
83 lines (75 loc) · 2.16 KB
/
index.html
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
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/2.5.0/fuse.min.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/css/materialize.min.css" />
<style type="text/css" media="screen">
.pageheader{
background-color : #176DC2;
}
body{
background-color: #FAFAFA;
}
</style>
</head>
<body>
<div class="row">
<div class="input-field col s8 push-s2 pull-s2 pageheader">
<div class="center">
<h5 class="center-align">
Fuzzy Search Logic - By Harshit
</h5>
</div>
</div>
</div>
<div class="row">
<div class="input-field col s8 push-s2 pull-s2">
<div class="col s1">
<label for="search">Search:</label>
</div>
<div class="col s7">
<input placeholder="Type Country Name" type="text" class="validate" id="search" name="search">
</div>
</div>
</div>
<div class="row">
<div class="input-field col s8 push-s2 pull-s2">
<div id="resultset">
<table id="result" class="responsive-table striped">
<tbody id="tablebody">
<tr>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
<script>
var result, fuse, tosearch;
var data = $.ajax({
url: "https://api.myjson.com/bins/1009i",
success: function(result) {
console.log(result);
}
});
var options = {
keys: ['name'],
id: 'name'
}
$('#search').keyup(function(e) {
tosearch = $("#search").val();
fuse = new Fuse(data.responseJSON, options);
result = fuse.search(tosearch);
populateResults();
});
function populateResults() {
$("#tablebody").empty();
$.each(result, function(index, value) {
$("#result tbody").append(
"<tr>" + "<td class=\"center-align\">" + value + "</td>" + "</tr>")
})
}
</script>
</html>