HELP. Dropdown filter driving me nuts.

The code appears to be working. It does the search function & pulls the categories into the dropdown, but it doesn’t filter from the dropdown. Here is the code:

import wixData from "wix-data";
 
$w.onReady(() => {
  loadCategories();
});
 
let lastFilterTitle;
let lastFilterCategory;
let debounceTimer;
export function iTitle_keyPress(event, $w) {
 if (debounceTimer) {
    clearTimeout(debounceTimer);
    debounceTimer = undefined;
  }
  debounceTimer = setTimeout(() => {
    filter($w('#iTitle').value, lastFilterCategory);  
  }, 500);
}
 
export function iCategory_change(event, $w) {
    filter(lastFilterTitle, $w('#iCategory').value);
}
 
function filter(title, category) {
 if (lastFilterTitle !== title || lastFilterCategory !== category) {
 let newFilter = wixData.filter();
 if (title)
      newFilter = newFilter.contains('showTitle', title);
 if (category)
      newFilter = newFilter.contains('category', category);
    $w('#dataset2').setFilter(newFilter);       
    lastFilterTitle = title; 
    lastFilterCategory = category;
  }
}
 
function loadCategories() {
  wixData.query('Categories')
      .find()
      .then(res => {
 let options = [{"value": '', "label": 'All Categories'}];
        options.push(...res.items.map(category => {
 return {"value": category.title, "label": category.title};
        }));
        $w('#iCategory').options = options;
      });
 
}

Here are my two data sets:

Does anyone know what I’m doing wrong? :confused:

Hello,

take a look at this working example, perhaps it will help you to solve your problem…
https://russian-dima.wixsite.com/meinewebsite/blank-3