Filter Dataset

Hey everybody! I am super new to Wix code. I need a quick explanation with copy/paste code of how to filter a database by a dropdown menu.

Basically, I’ve created a database for actors in my area. I want to be able to search this database and allow other filmmakers to search. I have the form all figured out and works great, and the dynamic page for each actor set.

I’m hoping to have a page with a gallery that features the headshots the actors have uploaded (I’ve figured out how to do this) and that can be filtered by different drop-down options. Actors can submit their age, race/ethnicity, build and gender by dropdown. I’d like to be able to filter the gallery by these queries. For example, if a filmmaker was looking for a fifty-year-old African-American heavyset man they could select that from the dropdown and actors who have entered in corresponding data would appear in the gallery.

Any help with this would be wonderful!

Hi,

Welcome to WixCode, where wonderful things happen.

Take a look at the post Let users filter data in a table . This will give you the code and examples to get started. Just apply the code to the Gallery items instead of the table items.

Have fun,

Yisrael

That worked! Thank you, Yisrael :slight_smile:

Hey everybody!
I am also quite new to the platform and also to JavaScript. I have a similar problem like emmaparkerfilmmaker, but unfortunately the solution, which was provided does not work for me.

Here is my problem:
I have a database (DataSet) with different Hotels. Each Hotel has a name (HName), different seasons, different Meal Categories, which can be selected, different rooms etc. In the end I want to filter my DataSet according to the Hotel Name, which was selected in a Dropdown (dropdown is linked to the database to display all available hotel names independent of filter). After having filtered only this Hotel, I want to search for the desired price (according to the season, selected meal and selected room type).

Here is my code:

export function DropH1Name_change(event) {
H1Name = $w(‘#DropH1Name’).value;
console.log('Name of Hotel 1: ’ + H1Name);
}

function searchHotelPrice (DataSet, HName, HMeal, HRoom, date) {
DataSet.setFilter(wixData.filter()
.contains(“name”, HName));
console.log(DataSet.getCurrentItem().name)

	let price = 0;																 
	
	if (date >= DataSet.getCurrentItem().s1_begin && date <= DataSet.getCurrentItem().s1_end){														 
		switch (HMeal) { 
			case "BB":  
				switch (HRoom) { 
					case "Single": price = DataSet.getCurrentItem().s1BbSingle; break; 
					case "Double": price = DataSet.getCurrentItem().s1BbDouble; break; 
					case "Triple": price = DataSet.getCurrentItem().s1BbTriple; break; 
					case "Quadruple": price = DataSet.getCurrentItem().s1BbQuadruple; break; 
					default: break;} 
				break; 
			case "HB": 
				switch (HRoom) { 
					case "Single": price = DataSet.getCurrentItem().s1HbSingle; break; 
					case "Double": price = DataSet.getCurrentItem().s1HbDouble; break; 
					case "Triple": price = DataSet.getCurrentItem().s1HbTriple; break; 
					case "Quadruple": price = DataSet.getCurrentItem().s1HbQuadruple; break; 
					default: break;} 
				break; 
			case "FB":  
				switch (HRoom) { 
					case "Single": price = DataSet.getCurrentItem().s1FbSingle; break; 
					case "Double": price = DataSet.getCurrentItem().s1FbDouble; break; 
					case "Triple": price = DataSet.getCurrentItem().s1FbTriple; break; 
					case "Quadruple": price = DataSet.getCurrentItem().s1FbQuadruple; break; 
					default: break;}	 
				break; 
			case "AIC":  
				switch (HRoom) { 
					case "Single": price = DataSet.getCurrentItem().s1AicSingle; break; 
					case "Double": price = DataSet.getCurrentItem().s1AicDouble; break; 
					case "Triple": price = DataSet.getCurrentItem().s1AicTriple; break; 
					case "Quadruple": price = DataSet.getCurrentItem().s1AicQuadruple; break; 
					default: break;} 
				break; 
			default: break; 
		}	 
	} else if { //much more code, basically the same as above only for other seasons 
            } else if { price =0; 
            } 
            return price; 

}

export function button1_click(event) {
let date = $w(‘#DatePickArrival’).value;
let cost = 0;
TotHotel1Cost = 0;
for (var i = 0; i < ArrHotel1Rooms.length; i++) {
cost = searchHotelPrice($w(‘#DataHotel’), H1Name, H1Meal, ArrHotel1Rooms[i], date);
TotHotel1Cost += cost;
}
$w(‘#text15’).text = String(TotHotel1Cost);
}

The problem is not getting the value out of a hotel, but first of all to find the hotel. Every time I click the button it gives me the correct cost, but all the time for the same hotel, independent of what H1Name is.

For example: H1Name is “Blue Sapphire Hotel” in Season 1, H1Meal=“FB”, Room Category = “Double” (stored in Array ArrHotel1Rooms). I now, ALWAYS get the cost for e.g. “World Wonders Hotel”, in the correct season 1, with correct meals (full board), room category (double) and therefore price.

What did I do wrong? I think it has something to do with DataSet.getCurrentItem(), because I thought that´s the way how to apply the filter. Is there any way how to set the Current Item?

Any help would be greatly appreciated!! Thanks a lot!