How to restore all data in the repeater after filtering it .

I’m filtering the repeater by one of the fileds , using this code :

import wixData from ‘wix-data’;
var lastSearch;
// when the browser window is ready, get unique items.
$w.onReady( function () {
uniqueItems();
});
// create unique list of items for dropdown
function uniqueItems(){
// get all data from database - maybe can improve to only get a single column
wixData.query(‘sanatorium’)
.find()
.then(data => {
// set the dropdown options
$w(“#placesDropdown”).options = buildOptions(createUniqueList(data.items, ‘place’));
})
//if could not get data from database, print the error to console.
. catch(function (e) {
console.log(JSON.stringify(e));
});
// subfunction to create a unique list of items
function createUniqueList(items, name) {
const namesOnly = items.map(item => item[name]);
namesOnly.sort();
return […( new Set(namesOnly))];
}
// build unique list options for dropdown
function buildOptions(uniqueList) {
return [getOptionItem(‘Выберите курорт из списка’, ‘’), …uniqueList.map(place => getOptionItem(place, place))];
}
function getOptionItem(label, value){
return {label:label, value:value};
}
}
// list based on data
export function placesDropdown_change(event) {
updateReapeater($w(‘#placesDropdown’).value);
}
/**

  • This function is a filter handler for repeater
  • The repeater is connected to #dataset1.
  • when we filter #dataset1, the repeated is automaticly updated.
    */
    function updateReapeater(search)
    {
    //if searched value that is not null and not equal to last search
    if (search && (lastSearch !== search)){
    //build a new filter using the search
    var searchFilter = wixData.filter().contains(‘place’, search);
    //filter using the new filter
    $w(‘#dataset1’).setFilter(searchFilter);
    }
    lastSearch = search;
    }

i want to be able to retrieve all data back and show in the repeater .
the page is : https://www.sanatorium-bg.info/sanatorium

up

I’ve faced a similar issue but managed to use the below code. The basic function of the code is to return any filter options you may have (tick boxes, search boxes, etc) and return them to their original state, then run the filter through the repeater again. The filter won’t have anything to apply so it will return the repeater to its original state with all the data.

//Add a reset button and add an onClick event
export function resetButton_click(event) {
        //Add all your filter objects here and have them undefined 
        $w("#searchBar").value = undefined;
        $w("#dropdown1").selectedIndex = undefined
        //Below is the filter you use to update the repeater
        ProductFilter();
        }
}

Please keep in mind I use this code with wixData.query where as you’re using a data-set search but the basics should be the same.

I hope this helps.

1 Like

i’ll try , thanx