Last active
May 30, 2019 15:29
-
-
Save AlekVolsk/38059aeb2edfab36881b7c3829f0012e to your computer and use it in GitHub Desktop.
Search on table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tableSearch(searchId, tableId) { | |
var phrase = document.getElementById(searchId); | |
var table = document.getElementById(tableId); | |
var regPhrase = new RegExp(phrase.value, 'i'); | |
for (var i = 1; i < table.rows.length; i++) { | |
flag = regPhrase.test(table.rows[i].cells[0].innerHTML); | |
if (flag) { | |
table.rows[i].style.display = ''; | |
} else { | |
table.rows[i].style.display = 'none'; | |
} | |
} | |
table.dispatchEvent(new Event('change', { 'bubbles': true })); | |
} | |
document.addEventListener('DOMContentLoaded', function () { | |
document.getElementById('input_search').addEventListener('keyup', function() { | |
tableSearch('input_search', 'table_search'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment