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