-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.js
88 lines (66 loc) · 2.76 KB
/
user.js
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
let status = window.localStorage.getItem("loginStatus");
function logout() {
window.localStorage.setItem("loginStatus", "false")
window.location.href = "./index.html";
}
var TableBody = document.getElementById("TableBody")
const getUsers = () => {
axios
.get("https://5fc1a1c9cb4d020016fe6b07.mockapi.io/api/v1/users")
.then(function (response) {
// handle success
var userData = response.data;
$("#SearchBox").on("keyup", function () {
let value = $(this).val()
console.log("The value Entered", value)
if ($(this).val() === "Enter") {
if (value.length < 2) {
alert("Please enter atleast 2 characters")
}
}
var users = searchedValue(value, userData)
search(users);
})
search(userData)
function searchedValue(value, userData) {
var filtereddata = []
for (let i = 0; i < userData.length; i++) {
value = value.toLowerCase()
var name = userData[i].fullName.toLowerCase();
if (name.includes(value)) {
filtereddata.push(userData[i])
}
}
return filtereddata;
}
function search(users) {
TableBody.innerHTML = ''
users.map((item) => {
return (
TableBody.innerHTML += ` <tr class="TableRow">
<td class="SecondaryText">${item.id}</td>
<td class="PrimaryText">
<img src=${item.profilePic}
alt="Profile Pic">
</td>
<td class="SecondaryText">${item.fullName}</td>
<td class="PrimaryText">${item.dob}</td>
<td class="SecondaryText">${item.gender}</td>
<td class="SecondaryText">${item.currentCity} , ${item.currentCountry}</td>
</tr>`
)
});
}
/* let arr2 = mydatas.filter((items) => {
return items.orderStatus == "Delivered" || items.orderStatus == "New" ;
});
*/
})
.catch(function (error) {
console.log(error);
})
.then(function () {
// always executed
});
};
getUsers();