Need help filtering a dataset with a dropdown + adding search

Hey friends!

I am trying to do something “simple” but I am still fairly new to coding so any help here is greatly appreciated.

Requirements:

  1. Dynamically search by team name

  2. Sort the repeating element that is connected to a dataset using dropdowns, one for year and the other for division

I have tried following along through forum posts and YouTube videos but I can’t seem to make it to the finish line on my own.

Webpage: https://www.hockeyfightsms.org/past-champions
(Incomplete/Not working) Code:

import wixData from 'wix-data';

// My search currently makes ALL data go away. And deleting my search term does not bring it back.

let debounceTimer;
export function iTitle_keyPress(event,$w) {
 if (debounceTimer) {
        clearTimeout(debounceTimer);
        debounceTimer = undefined;
    }
    debounceTimer = setTimeout(() => {
        filter($w('#iTitle').value);
    }, 200);
}

let lastFilterTitle;
function filter(title){
if (lastFilterTitle !== title) {
    $w('#dataset1').setFilter(wixData.filter().contains('teamName', title));
    lastFilterTitle = title;
    }
}

// I don't know how to write the correct function to make the drop-down filtering work

export function iYear_change(event) {
    yearChange();
}
function yearChange(){

}

Thanks!

Hello there
If your drop down has the id of iYear and the values contains years the below code would filter your dataset where the fieldKey is year and takes the value of the drop down as value for that filter.

function yearChange(){
  $w('#dataset1').setFilter(wixData.filter().eq('year', 
    $w("#iYear").value));
}

I hope that might help for you.

Thanks! Is the fieldKey the name of my field in the database or something else?

Hi Jess,

The field key reference to the field at your database but its not the filed name .
Take a look at the picture below:

Moreover, I suggest you to view this code about creating a search to a database:

Its reference to this video:

Best,
Sapir

Hi Jesse,

Looks like your code is working now- the webpage looks great!!

Do you mind sharing how you made it work?

Thank you!!

I couldn’t figure it out myself so I had to hire someone to custom code it. I’m not confident I could capture all of the work by posting a single snippet of code. :frowning:

Searching for a FILTER ?

https://www.media-junkie.com/pflegeservice