I’ve built a multiple filter alongside some help.
It is working as intended, however, all input fields have to have been filled out in order for the filter to work.
Is there a way of allowing a user to input in one field and the filter to still work?
I have tried changing this:
let dbFilter = searchName.and(searchMode).and(searchConduct).and(searchAge);
To this:
let dbFilter = searchName.or(searchMode).or(searchConduct).and(searchAge);
But it causes problems when people combine filters e.g. Search, dropdowns, sliders etc.
Any help would be appreciated
import wixData from 'wix-data';
let debounceTimer;
$w.onReady(function () {
wixData.query("GraveyardRecords")
.ascending("internedBy")
.distinct("internedBy")
.then(($dropBuild) => {
for (let i = 0; i < $dropBuild.items.length; i++) {
let $dropVal = $w('#conductedBy').options
$dropVal.push({ "label": $dropBuild.items[i], "value": $dropBuild.items[i] })
$w('#conductedBy').options = $dropVal;
}
})
$w('#search').onClick(() => {
let searchName = (wixData.filter().contains("firstName", $w('#searchInput').value)).or(wixData.filter().contains("lastName", $w('#searchInput').value))
let searchMode = wixData.filter().eq("mode", $w('#mode').value)
let searchConduct = wixData.filter().eq("internedBy", $w('#conductedBy').value)
let searchAge = (wixData.filter().ge("age", $w('#lowestAge').value)).and(wixData.filter().le("age", $w('#highestAge').value))
let dbFilter = searchName.and(searchMode).and(searchConduct).and(searchAge);
$w('#graveRecords').setFilter(dbFilter);
})
});
$w.onReady(() => {
$w('#clear').onClick(() => {
$w("#searchInput").value = undefined
$w("#lowestAge").value = 0
$w("#highestAge").value = 100
$w("#mode").value = undefined
$w("#conductedBy").value = undefined
$w("#sort").value = undefined
$w("#graveRecords").setFilter(wixData.filter())
})
})