I have taken below code from wix tutorials for search with one drop down filter. Now i have updated the code for dropdown2 for one more filter in my dynamic dataset.
Entire code is working fine but only issue i am facing for drop down option.
Example - if i filter using dropdown1 than dropdown 2 is showing all dropdown options (including empty data in the filter).
import wixData from "wix-data";
import {local} from 'wix-storage';
//These keys will hold the last search params in local storage
const PREV_TITLE = 'PREV_TITLE';
const PREV_CONTINENT = 'PREV_CONTINENT';
const PREV_CONTINENT1 = 'PREV_CONTINENT1';
let lastFilterTitle;
let lastFilterContinent;
let lastFilterContinent1;
$w.onReady(() => {
loadTeam();
});
let debounceTimer;
export function iTitle_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined; //what is this line for?
}
debounceTimer = setTimeout(() => {
filter($w('#iTitle').value, lastFilterContinent,lastFilterContinent1);
}, 500);
}
export function iContinent_change(event, $w) {
filter(lastFilterTitle, $w('#iContinent').value, lastFilterContinent1);
}
export function iContinent1_change(event, $w) {
filter(lastFilterTitle, lastFilterContinent, $w('#iContinent1').value);
}
function filter (title, continent, continent1) {
if (lastFilterTitle !== title || lastFilterContinent !== continent || lastFilterContinent1 !== continent1) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains('title', title);
if (continent1)
newFilter = newFilter.contains('consultantServices', continent1);
if (continent)
newFilter = newFilter.contains('city', continent);
$w('#dynamicDataset').setFilter(newFilter);
lastFilterTitle = title;
lastFilterContinent = continent;
lastFilterContinent1 = continent1;
}
//save for next session (and if it's empty, remove any old leftovers)
if (title)
local.setItem(PREV_TITLE, title);
else
local.removeItem(PREV_TITLE);
if (continent)
local.setItem(PREV_CONTINENT, continent);
else
local.removeItem(PREV_CONTINENT);
if (continent1)
local.setItem(PREV_CONTINENT1, continent1);
else
local.removeItem(PREV_CONTINENT1);
}
function loadTeam() {
wixData.query('Team')
.find()
.then(res => {
let options = [{
"value": '',
"label": 'All City'
}];
options.push(...res.items.map(continent => {
return {
"value": continent.city,
"label": continent.city,
};
}));
$w('#iContinent').options = options;
let options1 = [{
"value": '',
"label": 'All Category'
}];
options1.push(...res.items.map(continent1 => {
return {
"value": continent1.consultantServices,
"label": continent1.consultantServices,
};
}));
$w('#iContinent1').options = options1;
loadPrevSearch();
});
}
function loadPrevSearch() {
let prevTitle = local.getItem(PREV_TITLE);
let prevContinent = local.getItem(PREV_CONTINENT);
let prevContinent1 = local.getItem(PREV_CONTINENT1);
if (prevTitle) {
$w('#iTitle').value = prevTitle;
}
debugger;
if (prevContinent) {
$w('#iContinent').value = prevContinent;
}
debugger;
if (prevContinent1) {
$w('#iContinent1').value = prevContinent1;
}
if (prevTitle || prevContinent || prevContinent1) {
filter(prevTitle, prevContinent, prevContinent1);
}
}