summaryrefslogtreecommitdiff
path: root/static/filter.js
blob: 9318c237dd39ea2491c1a6662801840654c67b41 (plain)
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
// 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";
      }
    }
  }
}