summaryrefslogtreecommitdiff
path: root/static/filter.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/filter.js')
-rw-r--r--static/filter.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/static/filter.js b/static/filter.js
new file mode 100644
index 0000000..9318c23
--- /dev/null
+++ b/static/filter.js
@@ -0,0 +1,34 @@
+// Filter-search a table
+// Code expanded from this source: https://www.w3schools.com/howto/howto_js_filter_table.asp
+
+function filter() {
+ let selector, val;
+ selector = document.getElementsByName("select");
+
+ // Loop through the radio buttons to determine the filter-settings
+ for (let i = 0; i < selector.length; i++) {
+ if (selector[i].checked) {
+ val = parseInt(selector[i].value);
+ break;
+ }
+ }
+
+ let input, insensitive, table, tr, td, txtValue;
+ input = document.getElementById("search_history");
+ insensitive = input.value.toUpperCase();
+ table = document.getElementById("history");
+ tr = table.getElementsByTagName("tr");
+
+ // Loop through all table rows, and hide those that don't match the search query
+ for (let i = 0; i < tr.length; i++) {
+ td = tr[i].getElementsByTagName("td")[val];
+ if (td) {
+ txtValue = td.textContent || td.innerText;
+ if (txtValue.toUpperCase().indexOf(insensitive) > -1) {
+ tr[i].style.display = "";
+ } else {
+ tr[i].style.display = "none";
+ }
+ }
+ }
+}