Conditional Filtering Help Needed!

Hi All,

I really need some help in creating some conditional filters for my Wix Website. I have managed to create and write the code for the drop downs correctly by following the steps in the Video posted onto the Wix Community YouTube Channel by the Code Queen however, in the video she doesn’t explain how to then link these up to such things as a repeater, and this is exactly what I need!

The code I have used/in the video is below:

$w.onReady( function () {
uniqueDropDown1();
});

function uniqueDropDown1 (){
wixData.query(“doublefiltertest”)
.limit(1000)
.find()
.then(results => {

const uniqueTitles = getUniqueTitles(results.items);
$w(“#dropdown1”).options = buildOptions(uniqueTitles);
});

function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.colour);
return [… new Set(titlesOnly)];
}

function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
}

export function dropdown1_change(event, $w) {
uniqueDropDown2();
$w(“#dropdown2”).enable();
}

function uniqueDropDown2 (){
wixData.query(“doublefiltertest”)
.contains(“colour”, $w(“#dropdown1”).value)
.limit(1000)
.find()
.then(results => {

const uniqueTitles = getUniqueTitles(results.items);
$w(“#dropdown2”).options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.object);
return [… new Set(titlesOnly)];
}

function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
}

As I said, I really need to be able to link this up to a repeater, as well as including a ‘Reset’ button to put the filters and repeater back to the original state. I have tried testing this by created dropdowns called ‘Colour’ and ‘Object’. So for example, I would like to filter my repeater by ‘Red’ things and then filter by red objects such as:
Red > Ball/Button/Lollipop
Blue > Sky/Car/Water

I would really appreciate if anyone can help me on this as its the last thing I need to implement before my website is finished!

Thanks,
Luke

Luke you need to catch a dropdown2 change event. Then when that fires you need to setFilter() on the dataset that is bound to your repeater using the filter values from your drop down values. There are several questions with a more detailed version of this answer in the forum. Check out some of the answers to posts by hortiray.

Steve

Hi Steve,

Thanks for your speedy reply!

I appreciate that this may be a simple fix based on the forum you have referred me to however, I am quite poor when it comes to Wix Code and am struggling to adapt your reply on Horitrays forum to my issue.

I’d love it if we could have a more personal 1 on 1 chat to try help overcome this. If you (or anyone else reading this) could shoot me an email that would be great. I even don’t mind paying for your time if I have to, I just really need to get this fixed! You can reach me at:
lukeworthington1@outlook.com
or info@worthysites.co.uk

Thanks!

Luke

Luke, what is the page url that you need help with?

Hi Steve,

The page URL is https://lukeworthington1.wixsite.com/mysite-1

A bit of context:

SINGLE FILTER
On the single filter page, I have an example of everything working exactly how I’d like it to, the dropdowns filter the repeater and can then be reset with the big X button.
The example used is showing 4 different elements you could include at a function party. These are then filtered down by categories of Balloons, Entertainment and Catering.

DOUBLE FILTER
I have created a very simple repeater to show what I am looking to do. The repeater shows different objects and what colours those objects are. The aim of the two dropdowns is to be able to filter by colour and then by object, then to be able to reset the filters with a button, like on the single filter page. I seem to have created the dropdowns and linked them up to my data collections correct however, as I said, I am struggling to get them linked up to the repeater. I would also like to have the two dropdowns so that the second options only become visible once a choice for the first drowndown has been inputted.

Please note, the data for the two pages are not related, they are just two different examples.

I hope this all makes sense for you! You know where to reach me if not or need to explain in greater detail.

Thanks again for the help and have a great Christmas!

Luke

Hi Luke:

I developed an example page that does this a while ago. Here is a link:

This shows the working example and the code used to implement the example. What you need to look at is the code that handles the drop down change events. There is one per dropdown each of which uses the same function to aggregate filter values. The aggregated filter is then used to create a wixData filter that is used by the wix-dataset setFilter function() to filter the dataset used by the repeater.

See if you can map this example to your pages.

Cheers
Steve

Hi Steve,

Thanks for your response and efforts to try help me here.

As I have previously mentioned on here, I am really quite poor when it comes to the coding side of things and I’ve tried my best to apply using the website you have set up but I can honestly not do it. I don’t know what any of it means and I’m seeing error signs all over and not knowing how to action them so they go!

I would love if we could talk privately, possibly over Email to try to come to a positive conclusion here. As I’ve previously mentioned, I wouldn’t mind paying for your time as I really need to get this issue sorted and don’t have the skills to do so myself.

Email: lukeworthington1@outlook.com

You’ve been a great help so far, I’d love to see this through and finally get it working!

Thanks,
Luke

Hi Luke: Can you see if you can find help on the Wix Arena?
https://www.wix.com/arena/web-designers/1
This is where you will find someone who can do the work for you. As a Wix Employee I can’t do that :-).

Make sure you specifically request someone with Wix Code experience.

Cheers

Hi!!! Is your issue ok already? I am not an expert but my code for conditional formatting is perfectly working. My problem however, is that the dropdown list from the dataset is not loading from mobile view… Can anyone help me out?

Hi!!! Is your issue ok already? I am not an expert but my code for conditional formatting is perfectly working. My problem however, is that the dropdown list from the dataset is not loading from mobile view… Can anyone help me out?