Community X.

Connect with other creators, share ideas, give feedback and get the latest product updates.

Mar 10
Edited: Mar 10

1 Repeater, 1 Dropdown, & 1 Dataset

I tried following the tutorial with Creatively Nino. I also looked at different places trying to put the pieces together but unfortunately, I got nowhere.


I'm working on a sports schedule and it should be fairly easy but Editor X doesn't have a table like the older WIX had, which worked for me the first time around. I've been working on this since last year, trying to piece them together and the coding never seems to work right. I'm frustrated because it's dragging me out for way too long trying to figure this out.


The dropdown in Editor X doesn't seem to have onKeyPress so I use onChange, thinking it should work but didn't.


Thank you in advance.


import wixData from 'wix-data';

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

let lastFilterSchedule;

function filter (schedule) {
 if (lastFilterSchedule !== schedule) {
 let newFilter = wixData.filter();
 if (schedule) {
            newFilter = newFilter.contains('sports', schedule)
        }
        $w("#dataset2").setFilter(newFilter);
        lastFilterSchedule = schedule;
    }
}

function loadSchedule () {
    wixData.query("MS_Sports_Schedule").limit(1000).ascending("Sports").distinct("Sports").then((results) => {
 let distinctList = results.items.sport(element => {return {label: element, value: element};})
        distinctList.unshift({"value": "", "label": "All Sports"})
        $w("#Schedule").options = distinctList
    })
}
let onTime;

export function schedule_onChange(event) {
 //Add your code for this event here: 
 if (onTime) {
        clearTimeout(onTime)
        onTime = undefined;
    }
    onTime = setTimeout(() => {
        filter($w("#Schedule").value, lastFilterSchedule)
    }, 500)
}

export function Schedule_change(event) {
    filter(lastFilterSchedule, $w("#Schedule").value);
}

The database looks like this...





7 answers2 replies
1
Mar 10Edited: Mar 10

I tried this one too... didn't work either.


import wixData from "wix-data";

$w.onReady(() => {
  loadSports();
});

let lastFilterSports;

export function Schedule_onChange(event, $w) {
    filter(lastFilterSports, $w('#Schedule').value);
}

function filter(title, sports) {
 if (lastFilterSports !== title) {
 let newFilter = wixData.filter();
 if (title)
      newFilter = newFilter.contains('sports', title);

    $w('#dataset2').setFilter(newFilter);       
    lastFilterSports = title; 
  }
}

function loadSports() {
  wixData.query('MS_Sports_Schedule')
      .find()
      .then(res => {
 let options = [{"value": '', "label": 'All Sports'}];
        options.push(...res.items.map(sports => {
 return {"value": sports.title, "label": sports.title};
        }));
        $w('#Schedule').options = options;
      });

}


1
Mar 11

Have you tried to connect the dataset directly to the repeater? You will only need code for OnChange of the drop-down using SetFilter.

Mar 11

Yes, I have connected the dataset directly to the repeater. I changed it to SetFilter and it doesn't seem to be working either. hmmm...looks like I have to do a different route since I'm running out of time.


Thank you!

1
Mar 11

Hi, can you clarify what is not working? I assume the dataset shows in the repeater. Is the filter not working? Do you use the correct object name in the code? You will need to look up the technical name of the dataset connected to the repeater.

1
Mar 11

It's not showing the right schedule when I click one of the sports and I still get duplicates as well.




1
Mar 11

Do you have double lines in your table? If so you might want to split the table and have two datasets on your canvas. You can filter one dataset on the values of the other.

1
Mar 11Edited: Mar 11

Hey,

It seems to me that you have mixed several different functions here.

onKeyPress is a function that exists only for Inputs.

onChange is a function that only exists for dropdown.

The schedule_onChange function has a debounce that you just called by another name (onTime) but this only applies in case of Inputs > a user typing some value.

In addition, I see that you have blank lines in the database - it is better to delete them.


If you want, this is my email md60th@gmail.com, I will be happy to help you.

1
Mar 12

Finally, I got them to work! Thank you all for your help!

Mar 12

Glad to hear!

Editor X

Design your boldest creations.