showing results for - "how to search through a table javascript"
Bruno
31 Apr 2016
1(function() {
2  'use strict';
3
4  var TableFilter = (function() {
5    var Arr = Array.prototype;
6    var input;
7
8    function onInputEvent(e) {
9      input = e.target;
10      var table1 = document.getElementsByClassName(input.getAttribute('data-table'));
11      Arr.forEach.call(table1, function(table) {
12        Arr.forEach.call(table.tBodies, function(tbody) {
13          Arr.forEach.call(tbody.rows, filter);
14        });
15      });
16    }
17
18    function filter(row) {
19      var text = row.textContent.toLowerCase();
20      var val = input.value.toLowerCase();
21      row.style.display = text.indexOf(val) === -1 ? 'none' : 'table-row';
22    }
23
24    return {
25      init: function() {
26        var inputs = document.getElementsByClassName('table-filter');
27        Arr.forEach.call(inputs, function(input) {
28          input.oninput = onInputEvent;
29        });
30      }
31    };
32
33  })();
34
35 TableFilter.init();
36})();