Hey guys, how are you all?
Getting started as a 'coder' so forgive me if I`m asking some young, dumb & broke questions :)
1. I`ve found a 2-filter code (search + dropdown filter) at: https://www.wix.com/code/home/example/How-to-Create-a-Search-for-Your-Database-Collection
Now, obviously it works great, but I`m trying to add another drop down filter and can`t find the right way... This is my last attempt (and again - excuse me for being a real beginner):
$w.onReady(() => {
loadContinents();
});
let lastFiltertitle;
let lastFiltergender;
let lastFilterdiploma;
let debounceTimer;
export function iTitle_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w('#iTitle').value, lastFiltergender);
}, 500);
}
export function iContinent_change(event, $w) {
if ($w('#iContinent').value === "none") // Both (kind of a reset)
{
$w('#iTitle').value ='';
$w("#dataset1").setFilter( wixData.filter() );
lastFiltertitle="";
lastFiltergender="";
}
else
{
filter(lastFiltertitle, $w('#iContinent').value, lastFilterdiploma);
}
}
export function dropdown2_change(event, $w) {
if ($w('#dropdown2').value === "none") // Both (kind of a reset)
{
$w("#dataset1").setFilter( wixData.filter() );
lastFilterdiploma="";
}
else
{
filter(lastFiltertitle, lastFiltergender, $w('#dropdown2').value);
}
}
function filter(title, gender, diploma) {
if (lastFiltertitle !== title || lastFiltergender !== gender || lastFilterdiploma !== diploma) {
let newFilter = wixData.filter();
if (title) {
newFilter = newFilter.contains('title', title);
lastFiltertitle = title;
}
if (gender) {
newFilter = newFilter.contains('gender', gender);
lastFiltergender = gender;
}
if (diploma)
{
newFilter = newFilter.contains('diploma', diploma);
lastFilterdiploma = diploma;
}
$w('#dataset1').setFilter(newFilter);
}
}
function loadContinents() {
wixData.query('genders', 'diploma')
.find()
.then(res => {
let options = [{"value": '', "label": 'All genders'}];
options.push(...res.items.map(gender => {
return {"value": gender.title, "label": gender.title};
}));
$w('#iContinent').options = options;
});
}
title (iTitle) and gender (iContinent) are the original filters and I added the 'diploma'.
Tried to do it the same way as the title/gender code...
Of course, it wont work at all...
Trying to understand & learn.
Please guide me...
Thank you in advance,
Liron
@LRNS did you get this to work?
This query statement is incorrect:
wixData.query('genders', 'diploma')
A query statement applies to one collection. So, in order to retrieve the list of genders:
wixData.query('genders')
and in order to retrieve this list of diplomas:
wixData.query('diploma')
The results for each of the queries would then be used to populate the appropriate dropdown.
I hope this helps.