· 6 years ago · Dec 13, 2019, 07:28 PM
1 // LOGIN data being displayed in table.
2 $.getJSON(loginDataJson, function(data) {
3 // console.log(data);
4 var tableOutputsFromDeviceLogin;
5 $.each(data, function(key, val) {
6 tableOutputsFromDeviceLogin += "<tr><td>" + val.id + "</td><td>"+ val.visit_date + "</td><td>" + val.country + "</td><td>"+ val.browser + "</td><td>" + val.operatingSystem + "</td></tr>";
7 });
8 $("#visitsBody").html(tableOutputsFromDeviceLogin);
9
10 // Find a way to combine these three and search the return method accordingly.
11 // BROWSER FILTER
12 // Change API https://api.jquery.com/change/
13
14 $("#filterBrowser").change(function () {
15 // getting the selected Browser. https://api.jquery.com/selected-selector/
16
17
18 var userBrowserSelction = $("#filterBrowser option:selected").text();
19
20
21
22
23
24 console.log("User browser selction: " + userBrowserSelction);
25
26
27
28 var sortedArray;
29 // GREP function https://stackoverflow.com/questions/21172289/filtering-json-array-using-jquery-grep
30 sortedArray = $.grep(data, function (e) {
31 return (e.browser.indexOf(userBrowserSelction) == 0);
32 });
33 console.log(sortedArray);
34
35 $("#visitsBody tr").remove();
36
37
38
39
40 var updatedTableVariable;
41 $.each(data, function (key, val) {
42 // console.log(val.id);
43 updatedTableVariable += "<tr><td>" + val.id + "</td><td>" + val.visit_date + "</td><td>" + val.country + "</td><td>"
44 + val.browser + "</td><td>" + val.operatingSystem + "</td></tr>";
45 });
46 $("#visitsBody").html(updatedTableVariable);
47
48 });