Skip to content

Instantly share code, notes, and snippets.

@gabcarvalhogama
Last active January 16, 2019 14:31
Show Gist options
  • Save gabcarvalhogama/4f81b4d68de933ec170a7b19f1909a79 to your computer and use it in GitHub Desktop.
Save gabcarvalhogama/4f81b4d68de933ec170a7b19f1909a79 to your computer and use it in GitHub Desktop.
Filtro/Campo de Pesquisa para tabelas - JS
function tableFilter(input, tableSelector, index){
// Declare variables
var filter, table, tr, td, i;
filter = input.value.toUpperCase();
table = document.querySelector(tableSelector);
tr = table.getElementsByTagName("tr");
// Loop through all table rows, and hide those who don't match the search query
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[index];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment