feat: basic table display

This commit is contained in:
eneller
2025-03-16 13:12:17 +01:00
parent 677e85a0f7
commit 52998fa280
9 changed files with 78 additions and 36 deletions

View File

@@ -0,0 +1,28 @@
// needs to be included at bottom to get document references
const params = new URLSearchParams(window.location.search);
const searchInput = document.getElementById('searchInput');
const table = document.getElementById('table');
const table_r = Array.from(table.getElementsByTagName('tr'));
// allow search from url parameter
let searchParam = params.get('s');
if (searchParam){
searchInput.value = searchParam;
search(searchParam);
}
function submitSearch(event){
event.preventDefault();
search();
}
function search(searchStr = searchInput.value){
function showMatch(tr){
// match search with list
let searchSuccess = Array.from(tr.getElementsByClassName('table-data')).map(e => e.textContent)
.join(' ')
.indexOf(searchStr) > -1;
if (searchSuccess) tr.style.display = "";
else tr.style.display = "none";
}
table_r.map(showMatch, table_r);
}