Advertisement
badlogic

Search using javascript

Jul 25th, 2016
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  1. <script>
  2.     (function(document) {
  3.         'use strict';
  4.  
  5.         var LightTableFilter = (function(Arr) {
  6.  
  7.             var _input;
  8.  
  9.             function _onInputEvent(e) {
  10.                 _input = e.target;
  11.                 var tables = document.getElementsByClassName(_input.getAttribute('data-table'));
  12.                 Arr.forEach.call(tables, function(table) {
  13.                     Arr.forEach.call(table.tBodies, function(tbody) {
  14.                         Arr.forEach.call(tbody.rows, _filter);
  15.                     });
  16.                 });
  17.             }
  18.  
  19.             function _filter(row) {
  20.                 var text = row.textContent.toLowerCase(), 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('light-table-filter');
  27.                     Arr.forEach.call(inputs, function(input) {
  28.                         input.oninput = _onInputEvent;
  29.                     });
  30.                 }
  31.             };
  32.         })(Array.prototype);
  33.  
  34.         document.addEventListener('readystatechange', function() {
  35.             if (document.readyState === 'complete') {
  36.                 LightTableFilter.init();
  37.             }
  38.         });
  39.  
  40.     })(document);
  41. </script>
  42.  
  43.  
  44.  
  45.  
  46. //search in a table
  47.      <input type="text" class="light-table-filter form-control" data-table="order-table" placeholder="Filter" id="filterTable-input">
  48.        //table
  49.  <table class = "table table-condensed table-striped  order-table table">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement