Gallery filter works in preview but not live

  • My sandbox database is synced to live

  • Anyone has permission to view my database

It works exactly as I want in preview. If I open it live it shows all images and if I apply filters nothing happens.

code:

import {wixData} from 'wix-data';

function filterGallery (event,$w) {
    if($w('#radioGroup1').value === "best" && $w('#filter').value === "all" ){ 
        $w("#dataset1").setFilter(wixData.filter()
            .eq("best",Boolean(true)
            )
        )
    }else if ($w('#radioGroup1').value === "best" && $w('#filter').value !== "all"){
        $w("#dataset1").setFilter(wixData.filter()
            .contains("cat",$w('#filter').value)
            .eq("best",Boolean(true))
            )
    }else if ($w('#radioGroup1').value !== "best" && $w('#filter').value !== "all"){
        $w("#dataset1").setFilter(wixData.filter()
            .contains("cat",$w('#filter').value)
            )
    }else{
        $w("#dataset1").setFilter(wixData.filter())
    }
}

export function filter_mouseOut_1(event,$w) {
    filterGallery(event, $w)
}

export function radioGroup1_change(event,$w) {
    filterGallery(event, $w)
}

$w.onReady(function () {
    $w("#dataset1").setFilter(wixData.filter()
        .eq("best",Boolean(true))
        )
});

That’s what my filters look like:

You can see the live Version here: https://www.thenicklang.com/gallery

Thank you very much for your help!

Perhaps you should then check the permission of your database ?

I did, can’t find anything. Also, the images are visible on live, it’s just the filters that don’t work.

Do you have any reference fields on that database collection? That will also cause things to break.

Here are other things to look for:

https://www.totallycodable.com/post/data-visible-in-preview-but-data-not-visible-on-published-website

https://www.totallycodable.com/post/dropdown-list-doesn-t-work-as-intended-or-dropdown-is-disabled

And here is the link to other troubleshooting articles for the future, just in case:

https://www.totallycodable.com/categories/troubleshooting-tips

I’m curious to know what the problem is.

Sorry, I suggested the troubleshooting tips without even reading your code because you said it worked in preview.

Is there a reason why you used mouseOut instead on onChange for the dropdown?

I noticed you are using the event listeners directly from the property panel of the dropdown and radio button. Do they match what you have in the code? Did they accidentally get deleted? You can write the event code manually inside of you page onReady instead of using the properties panel. https://www.wix.com/corvid/reference/$w/dropdown/onchange

Inside of you onReady try adding onReady for the dataset first and then set the filter for the dataset. https://www.wix.com/corvid/reference/wix-dataset/dataset/onready

Also, instead of:
filterGallery ( event , $w )

Just type this:
filterGallery ();

Thank you. All I had to do was this:

Also, instead of:
filterGallery(event, $w)

Just type this:
filterGallery();

And because of that I also removed it where I define the function so it looks like this:

function filterGallery () {