Skip to content

Instantly share code, notes, and snippets.

@AlekVolsk
Last active May 30, 2019 15:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlekVolsk/38059aeb2edfab36881b7c3829f0012e to your computer and use it in GitHub Desktop.
Save AlekVolsk/38059aeb2edfab36881b7c3829f0012e to your computer and use it in GitHub Desktop.
Search on table
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