Two SEPERATE filters, one repeater.

Hello everyone,

I am creating a blog about food. On the ‘articles’ page I have a repeater and 2 Filters. One text input filter for the title and one dropdown menu to search on category. Until here it works fine.
I wanted the blog in two languages. But i know that that is not possible with databases and repeaters. So I found a workaround:

When the site is in english it displays the english title on the repeater and the 2 english filters. (dropdown and text input)

When the site is in dutch it displays the dutch title and the 2 dutch filters.

My problem is that i am not able to let the 2 english filters work together for the English title and Category and the Dutch filters work together for the dutch title and Category. But the english and Dutch filters have to be SEPERATE. I don’t want them to work togheter.

I tried this and the dutch work fine, but the english filters are not searching for the english title and Category, but also the dutch. In the code everything looks fine it think.

import wixData from 'wix-data';
import wixWindow from 'wix-window';

$w.onReady(() => {
  wixData.query('Categorie')
    .find()
    .then(res => {
 let options = [{"value": '', 'label': 'Allemaal'}];
      options.push(...res.items.map(status => {
 return {'value': status.title, 'label': status.title}
      }));
      $w('#dropdown1').options = options
    })
});

$w.onReady(() => {
  wixData.query('categorieEN')
    .find()
    .then(res => {
 let options = [{"value": '', 'label': 'All'}];
      options.push(...res.items.map(status => {
 return {'value': status.title, 'label': status.title}
      }));
      $w('#dropdown2').options = options
    })
});

let lastFilterTitle;
let lastFilterCategorie;
let debounceTimer;
export function input6_keyPress(event) {
 if (debounceTimer) {
    clearTimeout(debounceTimer);
    debounceTimer = undefined;
  }
  debounceTimer = setTimeout(() => {
    filter($w('#input6').value, lastFilterCategorie);
  }, 200);

}

let lastFilterTitleEN;
let lastFilterCategorieEN;
let debounceTimerEN;
export function input7_keyPress(event) {
 if (debounceTimerEN) {
    clearTimeout(debounceTimerEN);
    debounceTimerEN = undefined;
  }
  debounceTimerEN = setTimeout(() => {
    filter($w('#input7').value, lastFilterCategorieEN);
  }, 200);

}

function filter (title, categorie) {
 if (lastFilterTitle !== title || lastFilterCategorie !== categorie) {
 let newFilter = wixData.filter();
 if (title)
      newFilter = newFilter.contains('title', title);
 if (categorie)
      newFilter = newFilter.eq('categorie', categorie)
    $w('#dataset1').setFilter(newFilter);
    lastFilterTitle = title;
    lastFilterCategorie = categorie;
  }
 
}

function filterEN (titleEN, categorieEN) {
 if (lastFilterTitleEN !== titleEN || lastFilterCategorieEN !== categorieEN) {
 let newFilterEN = wixData.filter();
 if (titleEN)
      newFilterEN = newFilterEN.contains('titleEn', titleEN);
 if (categorieEN)
      newFilterEN = newFilterEN.eq('categorieEn', categorieEN)
    $w('#dataset1').setFilter(newFilterEN);
    lastFilterTitleEN = titleEN;
    lastFilterCategorieEN = categorieEN;
  }
 
}

export function dropdown1_change(event, $w) {
  filter(lastFilterTitle, $w('#dropdown1').value) 
}
export function dropdown2_change(event, $w) {
  filter(lastFilterTitleEN, $w('#dropdown2').value)
}

$w.onReady(function () {

let language = wixWindow.multilingual.currentLanguage;

if (language === 'en') {
    $w('#input7').show();
    $w('#dropdown2').show();
    $w('#text29').show();
    $w('#input6').hide();
    $w('#dropdown1').hide();
    $w('#text12').hide();

 
} else {
    $w('#input7').collapse();
    $w('#dropdown2').collapse();
    $w('#text29').collapse();
    $w('#input6').expand();
    $w('#dropdown1').expand();
    $w('#text12').expand();
 
}

});

input 7 = English text input filter
dropdown 2 = English dropdown filter
text29 = English title ON repeater

input6 = Dutch text input filter
dropdown 1 = Dutch dropdown filter
text 12 =Dutch title ON repeater

I really hope someone can help me with this.

Thanks in advance
Léon Missoul

Hi!

You should only have one page onReady per page on your site.

You could try removing the other page onReady functions and creating separate functions to call under the one page onReady function

You will find an example of how to query two database collections on one page on this post .

Hope this helps!

Dara | Corvid Team

Thanks a lot for your answer. I only have one onReady function? Right? The one above the if statement for the visibility of the elements. If i put the export functions inside it gives me errors. So how do i need to organize the code in order to make this work?
Thanks

Hi leonmissoul :raised_hand_with_fingers_splayed:

It’s possible, but it needs a lot of work, check out this multilingual Help Center, and how it shows the same articles in different languages.
https://nasriyasoftware.wixsite.com/nasriyaowl/help-center

But basically what you need to do is adding a reference field to the articles database, and filter the dataset normally if the language is the same as the articles language, and if the language is different, get the reference field ID, and query another collection that you’ve created earlier which holds the translations of the articles.

Hope that helped~!
Ahmad

Ok, wow, thanks for your answer! would you be able to help me modify the code in order to make it work? And could you privide me with some of the code needed? (maybe from the site you shared?) doesn’t have to be modified to my website. I can do that.

You CAN get the code from the page above, however, I don’t recommend doing that at all.

Every website is different in its specific needs, and this code might not work for you at all, what I do recommend, is getting ideas and apply them in your own way to suite your particular need.

It’s really needs long time and code to achieve these results, if you need assistance in a project , you can contact me on my profile , or submit your project to Wix Marketplace , and they’ll find a developer for you.

But a wix developer costs a lot right?

I don’t know how much they charge, you can submit your project to them and they’ll tell you how much it’ll cost, or you can contact me (links in my profile) too.

I contacted you through Whatsapp.

OK, one of the developers will reply asap.

I still don’t have an anwer! Any reply is welcome!

I still don’t have an anwer… could you help me a little bit? I’m not able to pay.

I already put you on track on how to start, that’s how I did it.