User input filter removes original filter on dynamic page

Hi,
Hope someone can help me here?
I’ve tried a simple user input filter on a dynamic page which lists hotels by type. The two types are HOTELS or LUXURY VILLAS / TENTS
https://www.infinittravel.com/AccommodationType/HOTELS
https://www.infinittravel.com/AccommodationType/LUXURY-VILLAS-%2F-TENTS

i’ve included a user input filter (with code) so that users can filter the properties by location/region.
unfortunately each time a region is selected the original filter which shows the property type for the page disappears and the filter shows all types. So instead of showing only the hotels in the list it shows all from the list.

Here is the code used

import wixData from ‘wix-data’;

$w.onReady(function () {

wixData.query(“Accommodation”)
.limit(1000)
.find()
.then(results => {

const uniqueItems = getUniqueItems(results.items);
$w(“#filterbyregion”).options = buildOptions(uniqueItems);
});

function getUniqueItems(items) {
const itemsOnly = items.map(item => item.region);
return […new Set(itemsOnly)];
}

function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return { label: curr, value: curr };

});

}

});

export function filterbyregion_change(event) {
let regionValue = $w(“#filterbyregion”).value;
$w(“#dataset1”).setFilter(wixData.filter().eq(“region”, regionValue));
}

Hope someone can help me figure this one out?
Thanks alot

You can hard code another filter parameter like this

export function filterbyregion_change(event) {
   let regionValue = $w("#filterbyregion").value;
   $w("#dataset1").setFilter(wixData.filter()
    .eq("region", regionValue)
    .eq("myField", "Hard Coded Value") //this one
   );
}

Hi Shan
Thanks for the reply really appreciate the help.
I tried this but there was no data showing at all. So it didnt work :frowning:

type is the field that shows either hotels or luxury villas (its a reference field - is that an issue)
What should I use for “Hard Coded Value”
.eq(“type”, “Hard Coded Value”)

@ruckshani Replace “Hard Coded Value” with the ID of the referenced item. In your case go to your “referenced” database and find the id of HOTELS or LUXURY VILLAS / TENTS .

To get the ID of either HOTELS or LUXURY VILLAS /TENTS go to their database and click on ‘Visible Fields’ and check ID

After that copy the ID of the item which will look like this

Your final code should be something like:

export function filterbyregion_change(event) {
   let regionValue = $w("#filterbyregion").value;
   $w("#dataset1").setFilter(wixData.filter()
    .eq("region", regionValue)
    .eq("type", "dc2a617c-17d0-4dfb-b49f-621882c4e42b") //this
   );
}

@shantanukumar847

Hi @Shan Thanks again but still no luck.

There are 2 IDs. This data is from the AccommodationType dataset
HOTELS
f8015d49-78a7-4917-ab70-67a7f1bf7744

LUXURY VILLAS / TENTS
32cccab8-489f-466e-a484-6a20f65acf44

Also this is a dynamic page it links from the AccommodationType dataset which holds these IDs. Data is populated in the repeater from Accommodation dataset where the property lists are. Do i need to create two separate pages instead of a dynamic page for this to work?