Hello,
I’ve been trying for hours now to get the added “Alle” option in my dropdown to work - by resetting the filter, so all the entries are shown in my repeater like before the entire filtering process. Being a beginner, I’ve followed a lot of tutorials. However, even when looking at other posts, none of the solutions seem to work…
This is my current code, I wonder what exactly is wrong with it?
import wixData from “wix-data” ;
$w . onReady (() =>{
loadThema ();
});
let lastFilterTitle ;
let lastFilterThema ;
let debounceTimer ;
export function searchBar_keyPress ( event , $w ) {
if ( debounceTimer )
{
clearTimeout ( debounceTimer );
debounceTimer = undefined ;
}
debounceTimer = setTimeout (()=> {
filter ( $w ( ‘#searchBar’ ). value , lastFilterThema )
}, 200 );
}
function filter ( title , thema ) {
if ( lastFilterTitle !== title || lastFilterThema !== thema )
{
let newFilter = wixData . filter ();
if ( title )
newFilter = newFilter . contains ( 'title' , title );
if ( thema )
newFilter = newFilter . contains ( 'thema' , thema );
$w ( '#dataset1' ). setFilter ( newFilter );
lastFilterTitle = title ;
lastFilterThema = thema ;
}
}
/**
- Adds an event handler that runs when an input element’s value
is changed.
Read more - @param {Event} event
*/
export function themaDropdown_change ( event ) {
// This function was added from the Properties & Events panel. To learn more, visit Velo: Working with the Properties & Events Panel | Help Center | Wix.com
// Add your code for this event here:
let filterType = $w ( ‘#themaDropdown’ ). value ;
if ( filterType === “Alle” ){
$w ( ‘#dataset1’ ). setFilter ( wixData . filter ());
} else {
filter ( lastFilterTitle , $w ( ‘#themaDropdown’ ). value );
}
}
function loadThema ( )
{
wixData . query ( ‘Thema’ )
. find ()
. then ( res =>{
let options = [{ “value” : ’ ’ , ‘label’ : ‘Alle’ }];
options . push (… res . items . map ( thema => {
return { “value” : thema . title , “label” : thema . title };
}));
$w ( ‘#themaDropdown’ ). options = options ;
});
}