Skip to content

Instantly share code, notes, and snippets.

@sublimecoder
Last active August 29, 2015 14:00
Show Gist options
  • Save sublimecoder/11189518 to your computer and use it in GitHub Desktop.
Save sublimecoder/11189518 to your computer and use it in GitHub Desktop.
filters the rows of a table. Make the table searchable.
// written in plain javascript and can be called using the inline html js events,
// or by using selectors of your favorite javascript library.
function disableEnterKey(e)
{
var key;
if(window.event)
key = window.event.keyCode; //IE
else
key = e.which; //firefox
return (key != 13);
}
//Filter for the table. You feed it the phase you are searching for and the ID of the table.
function tblFilter (phrase, _id){
var words = phrase.value.toLowerCase().split(" ");
var table = document.getElementById(_id);
var ele;
for (var r = 1; 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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment