Add: filterTable js function
This commit is contained in:
parent
bd613f7a42
commit
579e3ee569
2 changed files with 78 additions and 0 deletions
|
@ -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 %}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue