Trying to figure out a way to create a filter on a repeater that involves a few sets of selection tags. The issue I am running into is that I want to only sometimes apply the filter and some of the filters are negative. I tried looking at the examples in the API documentation but the .not() condition under filters only talks about queries.
export function selectionTags1_change(event) { $w('#dataset1').setFilter(wixData.filter() .hasSome("col1",$w('#selectionTags1').value)) //only if there is at least 1 tag selected .not(hasSome("col2",$w('#selectionTags2').value)) .hasSome(...) }
this works just fine for the simplest example with the first .hasSome. However what I also want is that if none of the tags are selected it is ignored so that particular .hasSome is not used.
I think for the dynamic part I can just do it in a few steps instead of trying to do it all at once.
var newFilter = wixData.filter() if($w('#selectionTags').selectedIndices[0] !== null){ newFilter = newFilter.hasSome(propertyName, value) }
and just build up the filter with the needed components. However I am not seeing any way to handle the inverse filter where it should exclude what has been selected. Am I missing something with the .not? it appears to only handle queries
I got it working. It appears that the .not() also accepts wixData.filter() objects instead of just wixData.query
function updateFilter(){ var filter3= $w('#tags3').selectedIndices[0] var filter2= $w('#tags2').selectedIndices[0] var filter1= $w('#tags1').selectedIndices[0] var newFilter = wixData.filter() if (tags1 !== undefined){ newFilter = newFilter.hasSome("col1",$w('#tags1').value) } if (tags2 !== undefined){ newFilter = newFilter.hasSome("col2",$w('#tags2').value) } if (allergies !== undefined){ newFilter = newFilter.not(wixData.filter().hasSome("col3",$w('#tags3').value)) } console.log("final filter",newFilter) $w('#dataset').setFilter(newFilter) }