Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TableFilter.js
/**
* 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