Database if statement

Hi all,

I have a database with shops in different cities and the products they offered.
I created a drop down to select city, and a repeater to show results.
So I have the following code

import wixData from ‘wix-data’;
$w.onReady(function () {
$w(“#dropdown1”).onChange(() => {
$w(“#dataset1”).setFilter(wixData.filter()
.eq(“city”, $w(“#dropdown1”).value));
});
});

In my database I have a column named “Workshops” and if the specific shop offers workshops the value in the field is “Workshop”

I want to created another page with a repeater, who will show only the shops offering workshops. So ideally I will have again only the dropdown menu with cities, and I need the repeater to show only those shops that offer workshop.
I was thinking of adding somewhere an if statement (if value in column “workshops” is “workshop” then show this entry to the repeater).
I do not want to create another database, as there are too many shops and it is getting to complicating.
Is there any way to do that or shall I go for another database?

Thank you!!!

Hi,
You can use the query function and manipulate the data however you want:

import wixData from 'wix-data';
$w.onReady(function () {

	$w("#dropdown1").onChange(() => {
	//getting relevant records from the collection
		wixData.query("collectionName")
			.eq("city", $w("#dropdown1").value)
			//column name , value
			.eq("workshops", "workshop")
			.find()
			.then((results) => {
				//setting all equivalent results 
				//to the repeater.
				$w("#repeater1").data = results;
			})
			.catch((err) => {
				let errorMsg = err;
			});
	});

	//setting the info to the repeater components
	$w("#repeater1").onItemReady(($w, itemData, index) => {
		$w(`#button1`).label = itemData.subPage;
		$w(`#button1`).link = itemData.url;
	});
});

I recommend also checking the repeater documentation here.

Good luck,
Tal.