-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchTable.js
51 lines (49 loc) · 1.97 KB
/
searchTable.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
document.addEventListener("DOMContentLoaded", () => {
document.querySelectorAll(".search-input").forEach((inputField) => {
const tableRows = inputField
.closest("table")
.querySelectorAll("tbody > tr");
const headerCell = inputField.closest("th");
const otherHeaderCells = headerCell.closest("tr").children;
const columnIndex = Array.from(otherHeaderCells).indexOf(headerCell);
const searchableCells = Array.from(tableRows).map(
(row) => row.querySelectorAll("td")[columnIndex]
);
inputField.addEventListener("input", () => {
const searchQuery = inputField.value.toLowerCase();
for (const tableCell of searchableCells) {
const row = tableCell.closest("tr");
const value = tableCell.textContent.toLowerCase().replace("-", " ");
row.style.visibility = null;
if (value.search(searchQuery) === -1) {
row.style.visibility = "collapse";
}
};
});
});
});
window.addEventListener('load',function(){
$('#addBorder').on('click',function(){
if (document.getElementById('addBorder').checked == true) {
$('#faSearchTable i').addClass('fa-border');
$('.moodleCode').each(function(){
$(this).text($(this).text().slice(0,-1)+" fa-border]");
});
console.log('border added')
}
else {
$('i').removeClass('fa-border');
$('.moodleCode').each(function(){
$(this).text($(this).text().slice(0,-11)+"]");
});
console.log('borders removed')
// $('tbody').addClass('d-none');
// $('tr').css('visibility','inherit');
// searchTable();
}
});
});
// $('tbody').css('visibility','hidden');
// $('td').css('border','none');
/*window.addEventListener("load",function(){
})*/