Hello !
So what I'm trying to do it to display element in a repeater that match the same "category" (reference field in the database) as the item currently displayed.
It won't let me select the dataset in the menu (see screenshot)
I tried this bit of code to apply the filter on the dataset but it doesn't work :
// 'goodies' is the database collection
//'collection' is the reference field that is set in the goodies database collection
//button31 displays the name of the collection the current item belongs to
let filter = wixData.filter();
filter = filter
.contains("collection", $w("#button31").label);
$w("#dataset4").setFilter(filter);
wixData.query("goodies")
.contains("collection", $w("#button31").label)
.find()
.then( (results) => {
let numberOfItems = results.totalCount;
// collapses the 'goodies smilaires' box if there are no results
if (numberOfItems <=1 ) $w("#box47").collapse;
});
I also want the repeater to collapse if there are none items to display.
So is that a bug or did I do something wrong here? Many thanks!
bump !
Hi !
So here's an update on the matter.
I managed to set the filter so the repeater show only items that belong to the same collection (reference field).
But that involves a (crappy) workaround.
I have added a button (#button63) (which will need to be hidden from the user...) that is linked to the collection ID of the current item.
Then I added this bit of code :
$w("#dataset4").onReady( () => { //shows only items related to the current item wixData.query("goodies"); let filter = wixData.filter(); filter = filter .hasAll("collection", $w("#button63").label); $w("#dataset4").setFilter(filter);
So until I find a more proper way to do this, I'm gonna stick to this...
But I still can't seem to have the box collapsed if the repeater returns 0 or 1 item...
I tried that :
let count = $w("#dataset4").getTotalCount() .hasAll("collection", $w("#button63").label); if (count <=1) $w("#box47").collapse;
but I first tried that :
wixData.query("goodies") .hasAll("collection", $w("#button63").label) .find() .then( (results) => { let numberOfItems = results.totalCount; // hides the 'goodies smilaires' box if there are no results if (numberOfItems <=1 ) $w("#box47").collapse; });
Strange because I have a similar bit of code that works.
wixData.query("commentaires") .contains("reference", $w('#input2').value) .find() .then( (results) => { let numberOfItems = results.totalCount; // set plural / singular versions of number of comments if (numberOfItems <=1 ) $w("#text96").text = numberOfItems + ' COMMENTAIRE'; else $w("#text96").text = numberOfItems + ' COMMENTAIRES'; if (numberOfItems >=2 ) $w("#commentsDropdown").show(); if (numberOfItems >=20 ) $w("#pagination1").show; });
The above code works.
Any idea why???
Hi Tristan!
Please check out this article ("Displaying Filtered Information (Master-Detail)" section) to see if everything is set up correctly in your collections: https://support.wix.com/en/article/about-displaying-content-from-multiple-database-collections-using-datasets
This article also may be useful: https://support.wix.com/en/article/displaying-content-from-multiple-database-collections-using-datasets
If you have checked everything and don't see the issue, then please send us a link to your site, so we can take a look at it.