Multi Language dropdown filter on dynamic page

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

$w.onReady(function () {
    let language = wixWindow.multilingual.currentLanguage;
    setFilterBasedOnLanguage(language);

    // Add onChange event handler for the dropdown
    $w("#dropdown1").onChange(() => {
        let selectedValue = $w("#dropdown1").value;
        applyDropdownFilter(selectedValue);
    });
});

function setFilterBasedOnLanguage(language) {
    if (language === "en") {
        $w("#dynamicDataset").setFilter(wixData.filter().eq("language", "EN"));
    } else if (language === "zh") {
        $w("#dynamicDataset").setFilter(wixData.filter().eq("language", "CH"));
    }
}

function applyDropdownFilter(value) {
    let targetDataset = $w("#dynamicDataset"); // Replace with the ID of the dataset you want to filter

    if (value) {
        targetDataset.setFilter(wixData.filter().eq("category", value));
    } else {
        targetDataset.setFilter(wixData.filter());
    }
}

export function newsRepeater_itemReady($w, itemData, index) {
    let language = wixWindow.multilingual.currentLanguage;
    setFilterBasedOnLanguage(language);
}

Hi, Friends! I got this problem and do not know how to solve. Hopefully anyone can help me, I really appreciate it.

the code above is used for displaying two languages on a dynamic page. It works, but if I add a drop down filter and connect it to my database, it shows all the categories in both language , and if I select any of the category and then select all, nothing will show up.

I have tried everything to make this work, but I failed.

Do you mean if you add another dropdown?

You’d then need to filter the new data in the same way that is done here.

Do also note that built-in support for multilingual content is coming to dynamic pages soon:

You can click the button to follow that feature request and get notified when it’s available.

1 Like