Help on connecting repeater to a filtered dropdown via dataset

@russian-dima Hello! Really appreciate your help! Again, i’ve looked through the code and tried to figure it out through the link you gave me but i’m such a novice, i’m struggling :frowning:

I’ve pasted below where i’m currently at with the code. Please help if you can.

After your instruction of " //-----loading of DropDown-Unique-Titles for all given DropDowns…" I have no idea if I have inputted the data correctly from there on down.

And then this bit >>
function FILTER_ENGINE() {
if ($w( ‘#switch2’ ).checked) {console.log( “Filter activated” )
let query = wixData.query(DATABASE).limit( 1000 )

is this related to a check box? Because I don’t have one of those.

It’s also saying “query is not defined”.

Thank you!


import wixData from 'wix-data';

//------------[User-Interface-----------------------------------------------------|
var DATABASE = "#newbuilddataset"
var REPEATER = "#repeater2"
var DropDowns= []
var MEMdropdowns = []
var DDprefix = "#sitedropdown, #locationdropdown, #advisordropdown"; //ID-prefix of all your dopdowns (DD1, DD2..)
//----------------------------------|
DropDowns[0] = "site"  ;  //column in your DATABASE ("title")
DropDowns[1] = "location"  ;  //column in your DATABASE 
DropDowns[2] = "advisor"  ;  //column in your DATABASE 
 
//------------[User-Interface-----------------------------------------------------|

//------------starting CODE-part when page loads.....
$w.onReady(function () { 
   load_uniqueTitles_DropDowns();
 //$w("#Button").onClick(()=>{ 
 //   $w("#newbuilddataset").setFilter(wixData.filter() 
 //   .eq("site", $w("#sitedropdown").value) 
 //   .eq("location", $w("#locationdropdown").value)
 //   .eq("advisor", $w("#advisordropdown").value));
 //});  
 
   $w('#sitedropdown').onChange(()=>{
      MEMdropdowns[0] = $w('#sitedropdown').value
      $w('#sitedropdown').enable();
      FILTER_ENGINE()
   })   
 
   $w('#locationdropdown').onChange(()=>{
      MEMdropdowns[1] = $w('#locationdropdown').value
      $w('#locationdropdown').enable();
      FILTER_ENGINE()
   }) 
 
   $w('#advisordropdown').onChange(()=>{
      MEMdropdowns[2] = $w('#advisordropdown').value
      $w('#advisordropdown').enable();
      FILTER_ENGINE()
   }) 
});

//-----loading of DropDown-Unique-Titles for all given DropDowns.....
async function load_uniqueTitles_DropDowns() {
 console.log("Load uniqueTitles for DropDowns")
 let dbDATA = await wixData.query(DATABASE)
 let Options = []

 for (var a = 0; a < DropDowns.length; a++) {
 if(DropDowns[a]!==undefined && DropDowns[a]!=="site" && DropDowns[a]!==null) {
 await dbDATA.distinct(DropDowns[a])
            .then((results) => {
 let items = results.items
 for (var b = 0; b <items.length; b++) {
                    Options.push([])    
                    Options[a].push({"location": items[b], "#locationdropdown": items[b]})
                }
                $w('#sitedropdown'+DDprefix+(a+1)).options = Options[a]
                $w('#locationdropdown'+DDprefix+(a+1)).placeholder = DropDowns[a]
            })
        }       
    }   
}
 
 function FILTER_ENGINE() {
 if ($w('#switch2').checked) {console.log("Filter activated")
 let query = wixData.query(DATABASE).limit(1000)
 
 //Filter-DropDowns-------------------------------------------
 for (let i=0; i < DropDowns.length; i++) {
 
 if (MEMdropdowns[i]!==undefined && MEMdropdowns[i]!=="undefined"){
            $w('#'+DDpräfix+(i+1)).value = MEMdropdowns[i]
            query =  query.eq(DropDowns[i], MEMdropdowns[i])
         }
      }
      query.find()
      .then(async res => {
 let itemData = await res.items          
          console.log(itemData)
          $w('#'+REPEATER).data = itemData
      })
   }
}