Dropdown & Search Filter - where am I going wrong?

I’d be so grateful for any help as am going mad trying to work this out. Both my dropdown filter and search button work fine if there are the first thing done on landing on the page.

If I filter by dropdown, hit clear and then use the search box it will only return a result IF the search term answer is in the filter for previous dropdown search.

The clear is resetting the dropdown and filter but is not clearing them in the background. If I leave the page and come back to it, it does completely clear them.

I’d be really grateful for any help.

Thanks!

import wixData from "wix-data";

$w.onReady(function () {
  $w("#image37").fitMode = "fit";
});

$w.onReady(() => {
 
  $w("#dataset2").onReady( () => {  
let options = $w("#iELType").options;
options.sort(function(a, b) {
let labelA = a.label.toUpperCase(); 
 let labelB = b.label.toUpperCase();
 if (labelA < labelB) {
 return -1;
  }
 if (labelA > labelB) {
 return 1;
  }
 return 0;
});
$w("#iELType").options = options;
})
 
  });

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

export function iELType_change(event) {
  filter(lastFilterTitle, $w('#iELType').value);
}

function filter(title, type) {
 if (lastFilterTitle !== title || lastFilterType !== type) {
 let newFilter = wixData.filter();
 if (title)
      newFilter = newFilter.contains('name', title);
 if (type)
      newFilter = newFilter.contains('type', type);
    $w('#dataset2').setFilter(newFilter);   
    lastFilterTitle = title; 
    lastFilterType = type;
  }
}

function loadExternalLinksType() {
  wixData.query('ExternalLinksType')
    .find()
    .then(res => {
 let options = [{"value": '', "label": 'All'}];
      options.push(...res.items.map(type => {
 return {"value": type.title, "label": type.title};
      }));
      $w('#iELType').options = options;
    });
}

export function clear_click(event) {
 
$w('#dataset2').setFilter(wixData.filter())
.then(()=>{
    $w("#iELType").value = "";
     $w("#iTitle").value = "";

})

}
1 Like

I would be grateful for any help - thanks!!