-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (39 loc) · 1.4 KB
/
script.js
File metadata and controls
44 lines (39 loc) · 1.4 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
document.addEventListener("DOMContentLoaded", function () {
fetch("stamp.json")
.then(response => response.json())
.then(data => {
const tableBody = document.getElementById("stampBody");
data.forEach(stamp => {
const row = document.createElement("tr");
row.innerHTML = `
<td>${stamp.id}</td>
<td>${stamp.name}</td>
<td>${stamp.country}</td>
<td>${stamp.year}</td>
<td><img src="${stamp.imageUrl}" alt="${stamp.name}" width="150"></td>
`;
tableBody.appendChild(row);
});
});
// Filter functionality
const filters = {
filterID: 0,
filterName: 1,
filterCountry: 2,
filterYear: 3
};
Object.keys(filters).forEach(filterID => {
document.getElementById(filterID).addEventListener("keyup", function () {
filterTable(filters[filterID], this.value.toLowerCase());
});
});
function filterTable(colIndex, filterValue) {
const rows = document.querySelectorAll("#stampTable tbody tr");
rows.forEach(row => {
const cell = row.cells[colIndex];
if (cell) {
row.style.display = cell.textContent.toLowerCase().includes(filterValue) ? "" : "none";
}
});
}
});