Show all under drop down box filter.

Hello, i tried searching the forum and google but still cannot find good answer on this.

After i found a successful code in doing filter, now im having a hard time for a solution where
you can choose show all on a drop box to reverse the filter.

I have 3 option on a dropdown box

  1. optional tours
  2. group departure
  3. free and easy

i’d like to add option SHOW ALL and filter will be reversed and show all items (inside a repeater)
here’s the code im using for filter.

import wixData from ‘wix-data’;

$w.onReady(() => {

wixData.query('ShowAll') 

    .find() 

    .then(res => { 

let options = [{“value”: “ShowAll”, “label”: “All Tours”}];

        options.push(...res.items.map(type => { 

return {“value”: type.search,“label”: type.search};

        })); 

    $w("#dropdownfilter").options = options; 

    }) 

});

let lastFilterSearch;

let lastFilterType;

let debounceTimer;

export function searchbar_keyPress_1(event, $w) {

//Add your code for this event here:

if (debounceTimer) {

    clearTimeout(debounceTimer); 

    debounceTimer = undefined; 

} 

debounceTimer = setTimeout(() => { 

    filter($w("#searchbar").value, lastFilterType); 

},200); 

}

function filter(search, type) {

if (lastFilterSearch !== search || lastFilterType !== type) {

let newFilter = wixData.filter();

if (search)

        newFilter = newFilter.contains('title',search); 

if (type)

        newFilter = newFilter.eq('tourCategory', type); 



$w("#dataset1").setFilter(newFilter); 

lastFilterSearch = search; 

lastFilterType = type; 

}    

}

export function dropdownfilter_change(event, $w) {

filter(lastFilterSearch, $w("#dropdownfilter").value); 

}

Hope someone can help me :slight_smile:

A query with Show all as you have coded:
wixData.query(‘ShowAll’)
will not return all items. There is no such query.

What you want to do is that if the user has selected the All option from the dropdown, the filter will be cleared, like this:
$w(" #dataset1 ").setFilter();
That is, to retrieve all items, you reset by using an empty filter. The dataset will then return all items since the results are not being filtered.

Thank you Yisrael for the fastest response on my inquiry.

Im just starting to learn coding and im not sure where can i put that code to show all items (reset filter) $w(" #dataset1 ").setFilter();

How should i set up this code or where in the part of the whole code should it paste it?
I will add an item with label “ALL” and values “ALL” on my dropdown. Do i need some tagging code?

Sorry for many questions.

Thank you so much