Thanks for the reply Ryan.
I managed to find a solution to the problem, from this forum thread. I basically just used his lines of code (which were pretty similar to my original code) in the last post.
Below is the code if anyone needs it
Now I just need a reset button that clears the filters, any tips here? I think I know the lines of code, but not sure where in the code to put them
import wixData from 'wix-data';
$w.onReady(function () {
});
//Restaurant filter
export function filterPlaces(){
let city = [];
let area = [];
let vibe = [];
let sunshine = [];
// Get the indexes of all the checkboxes checked in that group
let cityOptions = $w("#cityGroup").selectedIndices
let areaOptions = $w('#areaGroup').selectedIndices
let vibeOptions = $w('#vibeGroup').selectedIndices
let sunshineOptions = $w('#sunshineGroup').selectedIndices
let filter = wixData.filter();
// Next, loop through the checked items and add each field to the array and apply filter
if (cityOptions.length > 0){
for (var i = 0; i < cityOptions.length; i++) {
city.push($w('#cityGroup').options[cityOptions[i]].value);
}
}
if (city.length > 0) {
filter = filter.hasSome("city", city); //The "city" is a reference to the FiledKey in the database
}
if (areaOptions.length > 0){
for (var i2 = 0; i2 < areaOptions.length; i2++) {
area.push($w('#areaGroup').options[areaOptions[i2]].value);
}
}
if (area.length > 0) {
filter = filter.hasSome("area", area);
}
if (vibeOptions.length > 0){
for (var i3 = 0; i3 < vibeOptions.length; i3++) {
vibe.push($w('#vibeGroup').options[vibeOptions[i3]].value);
}
}
if (vibe.length > 0) {
filter = filter.hasSome("bestfor", vibe);
}
if (sunshineOptions.length > 0){
for (var i4 = 0; i4 < sunshineOptions.length; i4++) {
sunshine.push($w('#sunshineGroup').options[sunshineOptions[i4]].value);
}
}
if (sunshine.length > 0) {
filter = filter.hasSome("sunshine", sunshine);
}
$w("#dataset1").setFilter(filter)
.then(() => {
console.log("count after", $w("#dataset1").getTotalCount());
})
.catch((err) => {
console.log(err);
});
}
// Filter each time you click a check box in a group
export function cityGroup_change (event) {
filterPlaces();
}
export function areaGroup_change(event) {
filterPlaces();
}
export function vibeGroup_change(event) {
filterPlaces();
}
export function sunshineGroup_change_1(event) {
filterPlaces();
}
export function button4_click(event) {
filterPlaces()
}