My friend and I are trying to filter our dynamic page containing series of ‘cards’, each one containing a first name, last name, specialization, etc. There’s a dropdown menu at the top of the page with a button next to it allowing the user to select a certain specialization from the drop down. How can I filter the dynamic page to only show the cards containing that specialization?
I think wix says you can’t filter dynamic pages unless you use code, so here’s what we used:
import wixData from ‘wix-data’ ;
export function button9_click(event) { //our button was #button9
let value = $w( “#dropdown1” ).value;
let filter = wixData.filter();
$w( “#dynamicDataset” ).setFilter( . //name of dataset
filter.eq( “industrySpecialization” ) //does this need a second parameter of value?
);
}
What are we doing wrong/what can we change?
Hello Somil Vinod,
here you can see an example, how to work with filter…
https://russian-dima.wixsite.com/meinewebsite/blank-3
Thank you for the response but if anyone has anything a little more specific I’d appreciate it
Perhaps like that?
import wixData from'wix-data';
exportfunction button9_click(event) {start_Filter ()}
function start_Filter () {
let filter = wixData.filter()
let myValue = $w('#dropdown1').value
if ($w('#dropdown1').value!=0) {filter = filter.eq("industrySpecialization", myValue);}
}
This did not work either thank you for the response though!
Do you have some pics of your project? ( database / dynamic-page? )
Why my code does not work for you? What happens? What is the ERROR?
I just noticed, that there was a little typing-error in my code, perhaps this was the reason, why it did not work…
Try one more time…
export function button9_click(event) {start_Filter ()}
function start_Filter () {
let filter = wixData.filter()
let myValue = $w('#dropdown1').value
if ($w('#dropdown1').value!=0) {filter = filter.eq("industrySpecialization", myValue);}
}
I used your code, changed to .value!==0 because I believe you need 2 equals for the comparison. I think it is an issue with the button.
Hi Somil, russian-dima
It’s wrong to compare the value of the dropdown menu with 0, the value is a string used to identify the item inside the dropdown menu .
So either use this to check if no option is selected:
if ($w('#dropdown1').value !== undefined)
Or use this method:
if ($w('#dropdown1').selectedIndex !== 0)
Learn more about the value and selectedIndex and properties.
Hi, this didn’t work for filtering when I made the changes.
What is your actual code?
Which error do you get?
Some console-log-pics?
Just to write ----> that it didn’t work ----> bad idea
If you need more help, you can find contact-information in my profile.
Hey Somil
Try using this instead, which indicates that the value is defined as string but it’s empty.
if ($w('#dropdown1').value !== '')
I tested it out and it’s working.
Ahmad,
Here is the code after all the editing, and it is still not filtering the results.
import wixData from ‘wix-data’ ;
export function button_click(event) { start_Filter() }
function start_Filter() {
let filter = wixData.filter()
let myValue = $w( ‘#dropdown1’ ).value
if ($w( ‘#dropdown1’ ).value !== ‘’ ) { filter = filter.eq( “industrySpecialization” , myValue); }
}
Is there anyway where you can access our page/visit the website to see why it might not be working? The code makes complete sense but for some reason does not work.
Send me a message through the link on my profile and we’ll talk
Hi, if someone could help me with the same issue.
I have a dynamic page for posting job details and would like to have a dropdown to filter results by location, would be great if some one could help me the code in wix.
You can contact Ahmad…i am sure, he has already a prepared solution.
I hope he will find enough time to help you.
Good luck with this one. I am a Wix Partner and provided the code to request someone review it because it was not functioning. They replied with a few corrections that still didnt work. Now I am stuck and they remind me that they do not support assistance with coding issues. Jeez