Created
April 28, 2020 15:36
-
-
Save miwebguy/417160798c8c1b275a0d15d04bf01954 to your computer and use it in GitHub Desktop.
TableFilter.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
/** | |
* Table Filter | |
* @usage: <input type="search" onkeyup="Tablefilter(this, 'VReportList')" />\ | |
* where VReport is the id of the table body | |
*/ | |
function Tablefilter (phrase, _id) { | |
var words = phrase.value.toLowerCase().split(" "); | |
var table = document.getElementById(_id); | |
var ele; | |
for (var r = 0; r < table.rows.length; r++ ) { | |
ele = table.rows[r].innerHTML.replace(/<[^>]+>/g,""); | |
var displayStyle = 'none'; | |
for (var i = 0; i < words.length; i++) { | |
if (ele.toLowerCase().indexOf(words[i])>=0) { displayStyle = '';} | |
else { displayStyle = 'none'; break; } | |
} | |
table.rows[r].style.display = displayStyle; | |
} | |
} | |
function countDisplayedRows(_id) | |
{ | |
var hiddenRowCount = 0; | |
var table = document.getElementById(_id); | |
var rows = table.getElementsByTagName("tr"); | |
for (var i = 0; i < rows.length; i++) { | |
if(rows[i].style.display == 'none') hiddenRowCount++; | |
} | |
shown = rows.length - hiddenRowCount; | |
document.getElementById('DisplayCount').innerHTML = shown; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dfdgfg