Is there any way to get dataset filter?

I haven’t seen in the documentation anything like $w.dataset.getFilter();
And I’m wondering if there’s any way to retrieve the current filter (mostly relevant for dynamic pages).
Dataset Experts, the floor is yours.

2 Likes

Is it impossible as I think it is?
I’m asking because I have a dynamic category page and I need to add more filters to it.
To do that I need to get the initial filter first and to chain other filters to it.
I can get the filter through the page path of course, but it is more like a workaround.
There should be a way to retrieve the current filter.

Hi,

It’s possible to add several filters to your dataset using setFilter() function.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFilter

Best,
Sapir

@sapirh , That’s not what I asked. I know I can set filters.
My question is if I can get the current dataset filter.
Thank you!

Hi,

Currently, by code you can’t,

Best,
Sapir

Thanks

You can always assign it yourself:

const bar = {
    filter: wixData.filter(/*foo*/),
    active: false,
    change_active: function(bool) {
        this.active = bool;
    },
    get_active: function() {
        return this.active;
    }
}

$w('#dataset').setFilter(bar.filter).then(()=>{
    bar.change_active(true);
});

bar.get_active(); //true

Actually, this might be more like what you’re looking for:

const bar = {
    callFilter: function() {
        this.active = this.active ? false : true;
        return wixData.filter(/*foo*/),
    }
    active: false,
    get_active: function() {
        return this.active;
    }
}

$w('#dataset').setFilter(bar.callFilter());

bar.get_active(); //true

@skmedia thanks, but I needed it especially for filters that haven’t been set via my code (for example the automatic filter that’s set for dynamic pages or filters that are set via editor), and your code won‘t get me that of course.
( I can get along without this .getFilter() function that apparently doesn’t exist, but it could be nice to have it).