SetFilter function does not work according to docs?

I am trying to alter the filter in a dataset using buttons onClick.
According to API docs you should do…
import {wixData} from ‘wix-data’; // … $w(“#myDataset”).setFilter( wixData.filter() .startWith(“lastName”, “D”) .ge(“age”, “21”) );

But the console says that wixData.filter() is not a function and I can’t find it in intellisense suggestions either.

I tried this…
import {wixData} from ‘wix-data’; // … $w(“#pageElements”).setFilter( wixData.filter() .contains(“pageName”, “hotel”));

But it does not work… help needed.

It is possible to achieve the same results using the below code but no matter how I try the setFilter it does not work.

wixData.query(“pageElements”).eq(“pageName”, “hotel”).find().then((results) => {
let items = results.items;
let firstItem = items[0];

$w("#puffImage1").src = firstItem.puffImage1; 
$w("#puffImage2").src = firstItem.puffImage2; 
$w("#puffImage3").src = firstItem.puffImage3; 
$w("#puffImage4").src = firstItem.puffImage4; 

}); 

So the only thing I wonder is performance between the two of them?

Hi Andreas,

performance wise there is no significant difference, but Dataset may be more handy to use.

Your code looks fine and should work. Can you send me a link to your site I want to check to see if there are any issues?

P.S. Can you try changing your import to:

import wixData from 'wix-data'

Doing it without curly braces may improve auto-complete experience.

Hay Andreas,

In javascript there is actually a difference between

import wixData from 'wix-data';

and

import {wixData} from 'wix-data';

The first imports the module wixData, while the second imports the member wixData from the wix-data module. As the wix-data module does not have a wixData member, in the second case you get undefined which does not have a filter() method.

The following two forms are equivalent:

import wixData from 'wix-data';
let filter = wixData.filter;

and

import {filter} from 'wix-data';

Ok, then you should think about changing your docs and examples because you have it wrong then in all samples. Below from https://www.wix.com/code/reference/wix-dataset.html#setFilter.

import {wixData} from 'wix-data'; 
// ... 
$w("#myDataset").setFilter( wixData.filter() 
.startWith("lastName", "D") 
.ge("age", "21") 
);

Just for everyone else to not harass you with the same as I did :slight_smile:

Thanks for that, we are fixing it.