Hi,
Do I need to sort every filtered query along the line or filter all the queries first and do the sorting at the last query?
Thanks for any help!
For example:
wixData.query("myCollection").contains("price",$w("#dropdownprice").value))
.ascending("price")
.and(wixData.query("myCollection").contains("piece",$w("#dropdownpiece").value))
.ascending("piece")
.and(wixData.query("myCollection").contains("color",$w("#dropdowncolor").value))
.ascending("color")
.find()
.then( (results) => {
...and so on...
or
wixData.query("myCollection").contains("price",$w("#dropdownprice").value)) .and(wixData.query("myCollection").contains("piece",$w("#dropdownpiece").value)) .and(wixData.query("myCollection").contains("color",$w("#dropdowncolor").value))
.ascending("price", "piece", "color")
.find()
.then( (results) => {
...and so on...
or it does not matter.
Thank you.
amandam
January 31, 2022, 10:14pm
2
Hello! What is the end goal with the queries? What do you want the data to look like to the user after filtering?
amandam
January 31, 2022, 10:21pm
3
Follow up for clarity, that given what your goal is I’m thinking that you could maybe use query.hasAll() and then use one ascending call with multiple parameters .ascending (“a”,“b”,“c”)
Thanks Amanda,
I’ve already figured it out that I needed to do the sorting once at the end of each if() statement, like this:
if ( sort_option_in_dropdown === “PriceLowtoHigh” ){
wixData . query (“myCollection”) . contains ( “price” , $w ( “#dropdownprice ” ). value )) . and ( wixData . query (“myCollection”) . contains ( “piece” , $w ( “#dropdownpiece ” ). value )) . and ( wixData . query (“myCollection”) . contains ( “color” , $w ( “#dropdowncolor ” ). value )) . ascending (“price”)
. find ()
. then ( ( results ) => {
…and so on…
}
And do the if(){…} statement for each option in the dropdown menu
It works very good to me.
Fantastic! Glad you got it working.