Filtering a dataset

Could an expert help us?:grinning:

Maybe you can try this.
Keep the code in your on ready function.
Collapse the repeater.(in the property panel of the repeater)
Next ad a code bellow the code you added in the $w.onready
Where you say something like
$w(“#dataset”).onReady(()=>{
$w(“#repeater”).expand()
})
Its a long shot but it migh work.

I’m not at a computer atm and i’m olmost of to bed.
If it aint working i will reply as soon as possible

Kind regards,
Kristof.

So in short.
Collapse repeater in property panel.
Filter first
Then use the code for the dataset onready
In the codeblock of dataset onready expand the repeater.

I’m guessing an expert has not a solution???

Di you try my reply?

Maybe you can try this.
Keep the code in your on ready function.
Collapse the repeater.(in the property panel of the repeater)
Next ad a code bellow the code you added in the $w.onready
Where you say something like
$w(" #dataset “).onReady(()=>{
$w(” #repeater ").expand()
})
Its a long shot but it migh work.

I’m not at a computer atm and i’m olmost of to bed.
If it aint working i will reply as soon as possible

So in short.
Collapse repeater in property panel.
Filter first
Then use the code for the dataset onready
In the codeblock of dataset onready expand the repeater.

Kind regards,
Kristof.

@volkaertskristof Thx for the answer it gives me an error $w(" #dataset ").onReady(() is not a function…

@bilisanas
I don’t know what the name of your dataset is so change it to it.

$w(“#yourDatasetName”).onReady(()=>{
$w(" # yourRepeaterName ").expand()
})
if you didn’t change the name the name is probably dataset1 or dataset2 or something
Here is a reference link to the dataset onready reference.
https://www.wix.com/velo/reference/wix-dataset/dataset/onready

I did put it in a function

$w.onReady( function () {
$w( ‘#dynamicDataset’ ).onReady( () => {
var newFilter = wixData.filter();
newFilter = newFilter.contains( ‘name’ , “Cat” );
$w( ‘#dynamicDataset’ ).setFilter(newFilter);
$w( “#repeater1” ).expand()
})
})

it does not give an error but we have the same problem…repeater loads first all data then gets filtered… I think it gets confused with the dataset connection from the editor… I think has to be broken and built up from the beginning with coding…

Can an expert confirm?

@bilisanas

$w.onReady(function () {
var newFilter = wixData.filter();
newFilter = newFilter.contains('name', "Cat");
$w('#dynamicDataset').setFilter(newFilter)
    $w('#dynamicDataset').onReady( () => {
        ;$w("#repeater1").expand()    
    }) 
})

This is the right format to do it.
first filter then dataset.onready

Or if that didn’t work.
try it like this.

$w.onReady(async function () {
var newFilter = wixData.filter();
newFilter = newFilter.contains('name', "Cat");
await $w('#dynamicDataset').setFilter(newFilter)
    $w('#dynamicDataset').onReady( () => {
        ;$w("#repeater1").expand()    
    }) 
})

@volkaertskristof My friend of course i had changed the name of the dataset to mine…

Problem is not at naming… If you try it you will understand the problem…

$w.onReady( async function () {
var newFilter = wixData.filter();
newFilter = newFilter.contains( ‘name’ , “Cat” );
await $w( ’ #dynamicDataset ’ ).setFilter(newFilter)
$w( ’ #dynamicDataset ’ ).onReady( () => {
;$w( " #repeater1 " ).expand()
})
})

code you sent me works…! thank you…One last question how’s the syntax to the newFilter command to filter with the name “cat” and those containing the word “dog” in order to bring both results?

I want to bring the collections that containd the name “cat” and the collections that contain the name “dog”…

@bilisanas
Hi i tried the code myself and i didn’t had anyproblem with this.

$w.onReady( function () {
$w.onReady( async function () {
var newFilter = wixData.filter();
var filterCat = newFilter.contains( ‘type’ , “cat” );
var filterDog = newFilter.contains( ‘type’ , “dog” );

await $w( ‘#dataset1’ ).setFilter(filterCat.or(filterDog))
$w( ‘#dataset1’ ).onReady( () => {
$w( “#repeater1” ).expand()
})
})
});

This filters dog and cat

Don’t forget to change the dataset and repeater name since its my code.

kind regards,
Kristof.

‘type’ , “cat”
&
‘type’ , “dog”
to
‘name’ , “cat”
‘name’ , “dog”

@volkaertskristof I think we are close…this the error i get…

Mm
can you send the whole part of the code again
so i can see that nothing else has changed.
Also can you send a screenshot with the array opend in the console?

@volkaertskristof

import wixData from ‘wix-data’ ;

$w.onReady( function () {
$w.onReady( async function () {
var newFilter = wixData.filter();
var filterCat = newFilter.contains( ‘type’ , “cat” );
var filterDog = newFilter.contains( ‘type’ , “dog” );

await $w( ‘#dynamicDataset’ ).setFilter(filterCat.or(filterDog))
$w( ‘#dynamicDataset’ ).onReady( () => {
$w( “#repeater1” ).expand()
})
})
});

all the code i used is the above…

@volkaertskristof
import wixData from ‘wix-data’ ;

//$w.onReady(function () {
// $w(‘#dynamicDataset’).onReady( () => {
// var newFilter = wixData.filter();
//newFilter = newFilter.contains(‘name’, “Supplies”);
//$w(‘#dynamicDataset’).setFilter(newFilter);

//$w(“#repeater1”).expand()
// })
//})

$w.onReady( function () {
$w.onReady( async function () {
var newFilter = wixData.filter();
var filterCat = newFilter.contains( ‘type’ , “cat” );
var filterDog = newFilter.contains( ‘type’ , “dog” );

await $w( ‘#dynamicDataset’ ).setFilter(filterCat.or(filterDog))
$w( ‘#dynamicDataset’ ).onReady( () => {
$w( “#repeater1” ).expand()
})
})
});

The code i used is the above…
The grey one worked just perfect…
The other one with the or filtering is not

thx in advance…