Add: filterTable js function

This commit is contained in:
Aroy-Art 2024-08-24 09:55:53 +02:00
parent bd613f7a42
commit 579e3ee569
Signed by: Aroy
GPG key ID: DB9689E9391DD156
2 changed files with 78 additions and 0 deletions

View file

@ -99,4 +99,27 @@
</div>
</div>
<script>
function filterTable(tableId, columnIndex, input) {
console.log(tableId, columnIndex, input.value);
// Declare variables
var filter = input.toUpperCase();
var table = document.getElementById(tableId);
var rows = table.getElementsByTagName("tr");
// Loop through all table rows, and hide those who don't match the search query
for (var i = 0; i < rows.length; i++) {
var cells = rows[i].getElementsByTagName("td");
if (cells.length) {
var txtValue = cells[columnIndex].textContent || cells[columnIndex].innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
rows[i].style.display = "";
} else {
rows[i].style.display = "none";
}
}
}
}
</script>
{% endblock content %}