Last active
January 16, 2019 14:31
-
-
Save gabcarvalhogama/4f81b4d68de933ec170a7b19f1909a79 to your computer and use it in GitHub Desktop.
Filtro/Campo de Pesquisa para tabelas - JS
This file contains 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 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