Match words in any order in Isotope (using input value)
Can you try changing the following, I have removed the regex to string
filter: function(itemElem) {
return qsRegex ? itemElem.textContent.indexOf(qsRegex) !== -1 : true;
}
var quicksearch = document.querySelector('input[type="text"]');
quicksearch.addEventListener('input', function() {
// match items by first letter only
qsRegex = quicksearch.value; // Changed here
iso.arrange();
});
I ended up getting it working myself. I apologise, I'm still new to Javascript and am learning by trial and error, and I'm not sure how to give a proper explanation on how I got it working. But here is the final result:
var qsRegex;
var quicksearch = document.querySelector('input[type="text"]');
// init Isotope
var iso = new Isotope('#grid', {
itemSelector: '.item',
layoutMode: 'fitRows',
transitionDuration: 1000,
filter: function(itemElem) {
var qsRegex = [];
var resultRegex = [];
var endResult = new Boolean();
var searchID = quicksearch.value;
var searchTable = searchID.split(" ");
for (var i = 0; i < searchTable.length; i++) {
qsRegex[i] = new RegExp("(^|\\s)(" + searchTable[i] + ")", 'gi');
resultRegex[i] = qsRegex[i] ? itemElem.textContent.match(qsRegex[i]) : true;
endResult = endResult && resultRegex[i];
}
return endResult;
}
});
// use value of input to filter
var quicksearch = document.querySelector('input[type="text"]');
quicksearch.addEventListener('input', function() {
iso.arrange();
});
Updated jsfiddle link