Hello,
I would like a text component on a dynamic page to display the number of results found, for instance “X comments” (that match a certain criterion) or " X results found" (after filtering).
Any idea ? Thanks !
Hello,
I would like a text component on a dynamic page to display the number of results found, for instance “X comments” (that match a certain criterion) or " X results found" (after filtering).
Any idea ? Thanks !
I suggest you to write a code in order to get the number of results.
You didn’t write but I assume you want to filter results by the current item of the dynamic page.
You can use wix-dataset api in order to get the current item you want to filter by. (wix-dataset - Velo API Reference - Wix.com)
Afterwards, use wix-data to write the filter query (https://www.wix.com/code/reference/wix-data.WixDataFilter.html#contains) and the results of the length you can set to the text component you want
Hey, thanks !
I’m a real rookie in coding, I tried this in the onReady function (or should i put it in the dataset on ready ?)
let itemObj = $w("#dataset2").getCurrentItem();
wixData.query("commentaires")
.contains("reference", $w('#input2').value)
.find()
.then( (results) => {
let items = results.items;
$w('#text96').text === items + 'Commentaires';
} )
and it’s not working
Hey Tristan,
In order to get the number of items, not the items themselves, you need to use items.length, for example:
let numberOfItems = results.items.length;
$w('#text96').text === numberOfItems + 'Commentaires';
Good Luck,
Itai
Edit
Even simpler, the result object contains a totalCount
property which you can use.
So just use let numberOfItems = results.totalCount;
It’s cleaner.
See https://www.wix.com/code/reference/wix-data.WixDataQueryResult.html#totalCount
Still not working
let itemObj = $w("#dataset2").getCurrentItem();
wixData.query("commentaires")
.contains("reference", $w('#input2').value)
.find()
.then( (results) => {
let numberOfItems = results.totalCount;
$w('#text96').text === numberOfItems + 'Commentaires';
});
I tried this :
$w('#text96').text = numberOfItems + ' commentaires';
and it worked !
but the thing is it returns the total number of comments, not comments that contain this value :
.contains("reference", $w('#input2').value)
so this line doesn’t seem to work
EDIT : all I needed to do was to put that code in the datasetOnReady, it works now, thanks !
Hi ,
I look for code
Show only items matched in table
by mobile number
can you help me