I am using filters for my vacation rental site and it works great:
export function location_change() {
wixData.query(“Properties”)
.contains(“location”, “Queensland”)
.contains(“subLocation”, $w(‘#location’).value)
.contains(“type”, $w(‘#Type’).value)
.ge(“guests”, Number($w(“#Guests”).value))
.ge(“bedrooms”, Number($w(“#Rooms”).value))
.ge(“bathrooms”, Number($w(“#Bathrooms”).value))
.find()
.then((results) => {
$w(‘#repeater2’).data = results.items;
if (results.items.length === 0) {
$w(‘#box3’).show();
} else $w(‘#box3’).hide();
let value = $w(‘#location’).value;
if (value === ‘All’) {
$w(‘#box3’).hide();
wixData.query(“Properties”)
.contains(“location”, “Queensland”)
.find()
.then((results) => {
$w(‘#repeater2’).data = results.items;
});
}
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});
}
export function Type_change() {
wixData.query(“Properties”)
.contains(“location”, “Queensland”)
.contains(“subLocation”, $w(‘#location’).value)
.contains(“type”, $w(‘#Type’).value)
.ge(“guests”, Number($w(“#Guests”).value))
.ge(“bedrooms”, Number($w(“#Rooms”).value))
.ge(“bathrooms”, Number($w(“#Bathrooms”).value))
.find()
.then((results) => {
$w(‘#repeater2’).data = results.items;
if (results.items.length === 0) {
$w(‘#box3’).show();
} else $w(‘#box3’).hide();
let type = $w(‘#Type’).value;
if (type === ‘All’) {
$w(‘#box3’).hide();
wixData.query(“Properties”)
.contains(“location”, “Queensland”)
.contains(“type”, “”)
.find()
.then((results) => {
$w(‘#repeater2’).data = results.items;
});
}
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});
}
export function Guests_change(event, $w) {
wixData.query(“Properties”)
.contains(“location”, “Queensland”)
.contains(“subLocation”, $w(‘#location’).value)
.contains(“type”, $w(‘#Type’).value)
.ge(“guests”, Number($w(“#Guests”).value))
.ge(“bedrooms”, Number($w(“#Rooms”).value))
.ge(“bathrooms”, Number($w(“#Bathrooms”).value))
.find()
.then((results) => {
$w(‘#repeater2’).data = results.items;
if (results.items.length === 0) {
$w(‘#box3’).show();
} else $w(‘#box3’).hide();
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});
}
export function Rooms_change(event, $w) {
wixData.query(“Properties”)
.contains(“location”, “Queensland”)
.contains(“subLocation”, $w(‘#location’).value)
.contains(“type”, $w(‘#Type’).value)
.ge(“guests”, Number($w(“#Guests”).value))
.ge(“bedrooms”, Number($w(“#Rooms”).value))
.ge(“bathrooms”, Number($w(“#Bathrooms”).value))
.find()
.then((results) => {
$w(‘#repeater2’).data = results.items;
if (results.items.length === 0) {
$w(‘#box3’).show();
} else $w(‘#box3’).hide();
if (($w("#location").value === 'All')) {
$w("#location").selectedIndex === undefined;
}
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});
}
export function Bathrooms_change(event, $w) {
wixData.query(“Properties”)
.contains(“location”, “Queensland”)
.contains(“subLocation”, $w(‘#location’).value)
.contains(“type”, $w(‘#Type’).value)
.ge(“guests”, Number($w(“#Guests”).value))
.ge(“bedrooms”, Number($w(“#Rooms”).value))
.ge(“bathrooms”, Number($w(“#Bathrooms”).value))
.find()
.then((results) => {
$w(‘#repeater2’).data = results.items;
if (results.items.length === 0) {
$w(‘#box3’).show();
} else $w(‘#box3’).hide();
if (($w("#location").value === 'All')) {
$w("#location").selectedIndex === undefined;
}
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});
}
What I would like to do is have a sort by price descending & ascending.
This code works perfectly:
export function dropdown1_change(event, $w) {
$w(“#dataset1”).setSort(
wixData.sort()
.descending(“price”));
if ($w(‘#dropdown1’).value === ‘low’)
$w(“#dataset1”).setSort(
wixData.sort()
.ascending(“price”));
if ($w(‘#dropdown1’).value === ‘none’)
$w(“#dataset1”).setSort(
wixData.sort()
);
}
However, it works only on the unfiltered data . I would like users to be able to combine it with my filters as above, so it works before you filter, then you filter and then you can sort the results as well.
Can you please let me know how I would go about that? Thank you!!