-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrcs.js
70 lines (61 loc) · 2.3 KB
/
crcs.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
document.addEventListener("DOMContentLoaded", function() {
const sortSelect = document.getElementById("sort-select");
const monthFilterContainer = document.getElementById("month-filter-container");
sortSelect.addEventListener("change", function() {
if (sortSelect.value === "month") {
monthFilterContainer.style.display = "block";
} else {
monthFilterContainer.style.display = "none";
}
sortTable();
});
const monthFilter = document.getElementById('month-filter');
const table = document.querySelector('table');
const tableBody = table.querySelector('tbody');
let tableRows = Array.from(tableBody.querySelectorAll('tr'));
monthFilter.addEventListener('change', filterTableByMonth);
function sortTable() {
const sortBy = sortSelect.value;
if (sortBy === 'default') {
// Reset table to original order
tableRows.forEach(row => {
tableBody.appendChild(row);
});
} else if (sortBy === 'month') {
tableRows.sort((a, b) => {
const dateA = new Date(a.cells[5].textContent);
const dateB = new Date(b.cells[5].textContent);
return dateA.getMonth() - dateB.getMonth();
});
} else if (sortBy === 'state') {
tableRows.sort((a, b) => {
const stateA = a.cells[3].textContent.toLowerCase();
const stateB = b.cells[3].textContent.toLowerCase();
return stateA.localeCompare(stateB);
});
} else if (sortBy === 'name') {
tableRows.sort((a, b) => {
const nameA = a.cells[1].textContent.toLowerCase();
const nameB = b.cells[1].textContent.toLowerCase();
return nameA.localeCompare(nameB);
});
}
tableRows.forEach(row => {
tableBody.appendChild(row);
});
// Update tableRows after sorting
tableRows = Array.from(tableBody.querySelectorAll('tr'));
}
function filterTableByMonth() {
const filterByMonth = monthFilter.value;
tableRows.forEach(row => {
const dateCell = row.cells[5];
const month = dateCell.textContent.split('/')[1];
if (filterByMonth === '' || month === filterByMonth) {
row.style.display = '';
} else {
row.style.display = 'none';
}
});
}
});