Hey guys!
I’ve seen a couple of posts somewhat related to this question, but I haven’t quite found a solution yet.
So, I have a repeater that is filtered by a ‘location’ dropdown (#Location), which is populated by a database with a list of countries, and a set of selection Tags (#Tags)
Now, when the page loads, I want to set a default value on the ‘Location’ dropdown which also works the filter in the repeater, thus only showing the items in that specified location. The ‘settings’ section of the dropdown offers to select an item from the list as default, but it doesn’t actually give me a choice from the actual options - I’m guessing this has something to do with it being populated by a database.
Problem is, I’ve tried a bunch of different codes, and from what I understand, something like this should work:
$w . onReady ( () => {
$w ( “#dataset3” ). onReady ( () => {
$w ( “#Location” ). selectedIndex = Number [ 0,2 ]
} );
} )
However, it doesn’t seem to work. Nothing I’ve done makes the filter work based on the default value. This seems like it should be really simple, so I’m not too sure what to do?
Also, here is the code for my filter, in case that would help:
//Default Location setting - Test
$w . onReady ( () => {
$w ( “#dataset3” ). onReady ( () => {
$w ( “#Location” ). selectedIndex = Number [ 162 ]
} );
} )
//NEW FILTER
$w . onReady ( function () {
$w ( "#Location, #Tags" ). onChange ( function () {
search ();
$w ( "#selectionTags1" ). value = **undefined** ;
});
function search () {
let filter = wixData . filter ();
let catIdx = $w ( "#Location" ). selectedIndices ;
let tagIdx = $w ( "#Tags" ). selectedIndices ;
let tag2Idx = $w ( "#Tags" ). selectedIndices ;
let category = $w ( "#Location" ). value ;
let tags = $w ( "#Tags" ). value ;
let tags2 = $w ( "#Tags" ). value ;
if ( catIdx . length > 0 || tagIdx . length > 0 || tag2Idx . length > 0 ) {
filter = filter . hasSome ( "locationTags" , category )
. or ( filter = filter . hasSome ( "propertytype" , tags ))
. or ( filter = filter . hasSome ( "propertytype" , tags2 ))
$w ( "#dataset1" ). setFilter ( filter )
. then ( count )
} **else** {
$w ( "#dataset1" ). setFilter ( filter )
. then ( count )
}
$w ( "#selectionTags1" ). onClick ( function () {
$w ( "#Location, #Tags" ). value = **undefined** ;
$w ( "#dataset1" ). setFilter ( wixData . filter ()). then ( count );
});
}
//COUNT ITEM
function count () {
let count = $w ( "#dataset1" ). getTotalCount ();
if ( count > 0 ) {
$w ( "#countText" ). text = ` ${ count } items found` ;
} **else** { $w ( "#countText" ). text = `No item found` ; }
**return** count ;
}
$w ( "#dataset1" ). onReady ( function () {
count ();
});
});
//NEW FILTER END
Would greatly appreciate some pointers on this one, guys!
Thanks!