Filter all

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();
}

Hi Splatty

I recently did something similar. What I did was to add another dropdown for the person entering the data into the database, and then added another db field. In this one, I set the value fo the dropdown item to contain two words, i.e. the proerty type & “All”.

I then continued to add code for my frontend search to ‘contain’ either of the words, i.e. the property type or ‘All’. This did the trick.

Thanks Tiaan. I would like to keep it with code and not have to add more to the database if possible. Hopefully the wix guys can help!

Can any of you Wix legends help please?