Hi!
In short, my site is a car guide. I have a dynamic page, which shows all the models from a given car brand by filtering a database with it’s location ID. So far, so good!
Now, i’m trying to add vehicle type tags to the dynamic page so for example, if an user is in the BMW site and wants to see the brand’s SUVs, he just has to click on the SUV Tag.
The problem is, when clicking on tags, the repeater unfilters itself and shows SUVs from the whole database (not just from the filtered BMW data).
I’m a complete a rookie coding, but here’s the code i’m currently using. What should i add so when clicking on tags, the repeater maintains the filtered data?
Thanks in advance for your help,
Best regards,
JP.
Site name: autonomic . com . co
import wixData from ‘wix-data’ ;
$w.onReady( function () {
var locationId = $w( ‘#dynamicDataset’ ).getCurrentItem()._id;
$w( ‘#dataset1’ ).setFilter(
wixData.filter()
.eq( ‘locationId’ , locationId));
$w( “#repeater2” ).onItemReady( ($w, itemData, index) => {
$w( “#repeater2” ).show();
});
});
$w.onReady( function () {
$w( “#button3” ).target = “_self” ;
});
$w.onReady( function () {
$w( “#image49” ).target = “_self” ;
});
$w.onReady(() => {
waitForLoading();
});
export function button6_onClick() {
$w( ‘#preloader’ ).show();
waitForLoading();
}
function waitForLoading() {
setTimeout(() => {
$w( ‘#preloader’ ).hide( ‘FadeOut’ );
}, 1500 );
}
const collectionName = ‘BrandCatalogPhotos’ ;
const fieldToFilterByInCollection = ‘tags’ ;
$w.onReady( function () {
loadDataToRepeater();
$w( '#tag' ).onChange((event) => {
const selectedTags = $w( ‘#tag’ ).value;
loadDataToRepeater(selectedTags);
})
});
function loadDataToRepeater(selectedCategories = ) {
let dataQuery = wixData.query(collectionName);
if (selectedCategories.length > 0 ) {
dataQuery = dataQuery.hasAll(fieldToFilterByInCollection, selectedCategories);
}
dataQuery
.find()
.then(results => {
const itemsReadyForRepeater = results.items;
$w( ‘#repeater2’ ).data = itemsReadyForRepeater;
const isRepeaterEmpty = itemsReadyForRepeater.length === 0
})
}