I have some data stored in a table I would like to filter using Javascript. I type my filter string in an input field and show only rows which match.
But now, I would like to do this : for example, if I type value1|value2 in my filter field, I want only rows which match with these 2 strings (value1 AND value2). I've tried many ways to do it but no one does exactly what I want ...
Here is an example of what I use to filter (works with one string) :
function filterFromName(text) {
// Variables
var filter, tableData, tr, td, i;
filter = text.toUpperCase();
tableData = document.getElementById('data_values');
tr = tableData.getElementsByTagName('tr');
// For each table row, hide those who don't match the search text
for (i = 0; i< tr.length; i++) {
td = tr[i].getElementsByTagName('td')[1]; // query the Alias column
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1)
tr[i].style.display = "";
else
tr[i].style.display = "none";
}
}
}
Is there a way to adapt this piece of code to do what I want?
|as the and (opposed to using+as|is rather an or)