-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
50 lines (46 loc) · 1.79 KB
/
script.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
document.addEventListener('DOMContentLoaded', function () {
const labelFilter = document.getElementById('labelFilter');
const tableRows = document.querySelectorAll('#talksTable tbody tr');
function populateFilterOptions() {
const labelSet = new Set();
tableRows.forEach(row => {
const labels = row.getAttribute('data-labels').split(', ');
labels.forEach(label => labelSet.add(label));
});
labelSet.forEach(label => {
const option = document.createElement('option');
option.value = label;
option.textContent = label;
labelFilter.appendChild(option);
});
}
function filterTable() {
const selectedLabel = labelFilter.value;
tableRows.forEach(row => {
const labels = row.getAttribute('data-labels').split(', ');
if (selectedLabel === 'all' || labels.includes(selectedLabel)) {
row.style.display = '';
} else {
row.style.display = 'none';
}
});
}
function sortTable() {
const tbody = document.querySelector('#talksTable tbody');
const tableRowsArray = Array.from(tableRows);
tableRowsArray.sort((rowA, rowB) => {
const yearA = parseInt(rowA.querySelector('td:nth-child(3)').textContent);
const yearB = parseInt(rowB.querySelector('td:nth-child(3)').textContent);
return yearB - yearA;
});
// Remove existing rows
while (tbody.firstChild) {
tbody.removeChild(tbody.firstChild);
}
// Append sorted rows
tableRowsArray.forEach(row => tbody.appendChild(row));
}
populateFilterOptions();
sortTable();
labelFilter.addEventListener('change', filterTable);
});