Hi guys, What should be a simple thing I just can’t figure out!
I am filtering my repeater properties by type and have them listed as either houses or hotels in the database and this works great. However I also have an "ALL’ category in the dropdown which I want to list all properties obviously and I can’t work out how to code this? No properties are listed all in the database obviously so it needs to be identified somehow
Full code here:
import wixData from ‘wix-data’;
let originalPropertiesInfo = [];
let filteredResults = [];
$w.onReady(function () {
//Query to get the information from the database
wixData.query(“Queensland”)
.find()
.then((results) => {
originalPropertiesInfo = results.items;
$w(#repeater2
).data = originalPropertiesInfo;
})
.catch((err) => {
let errorMsg = err;
});
//Set the information to the repeater
$w(#repeater2
).onItemReady(($w, itemData) => {
//add here all the relevant elements of the repeater
//In this case, I’ve added a text and an image to the repeater
$w(#text52
).text = itemData.title;
$w(‘#image2’).src = itemData.images;
$w(#text53
).text = itemData.people;
$w(#text50
).text = itemData.bedrooms;
$w(#text51
).text = itemData.bathrooms;
$w(#text49
).text = itemData.description;
});
});
function filterResults() {
filteredResults = [];
const type = $w(‘#Type’).value;
const guests = $w(‘#Guests’).value;
const rooms = $w(‘#Rooms’).value;
const bathrooms = $w(‘#Bathrooms’).value;
if (type && type !== 'Choose type of accommodation') {
filteredResults = originalPropertiesInfo.filter(item => item.type === type);
}
if (guests && guests !== 'Choose number of guests') {
filteredResults = originalPropertiesInfo.filter(item => item.people >= guests);
}
//after the first if statement, the results is filtered by state
if (rooms && rooms !== 'Choose number of beds') {
filteredResults = originalPropertiesInfo.filter(item => item.bedrooms >= rooms);
}
if (bathrooms && bathrooms !== 'Choose number of bathrooms') {
filteredResults = originalPropertiesInfo.filter(item => item.bathrooms >= bathrooms);
}
//results is filtered by both guests and rooms
Guests_change();
}
export function Guests_change(event) {
//filtering the results
//setting the data
$w(‘#repeater2’).data = filteredResults;
//setting the repeater elements
$w(‘#repeater2’).forEachItem(($w, itemData, index) => {
$w(`#text52`).text = itemData.title;
$w('#image2').src = itemData.images;
$w(`#text53`).text = itemData.people;
$w(`#text50`).text = itemData.bedrooms;
$w(`#text51`).text = itemData.bathrooms;
$w(`#text49`).text = itemData.description;
});
}
export function refine_onClick(event, $w) {
filterResults();
}