Repeater help.

trying to pull a single line from a dataset to show in a repeater alone. How? I am trying to allow the repeater to find one piece of information like an email address and then showing the entire entry on that line in the repeater.

I know that I will need to use the find. api

Many thanks for the help.

It’s not so clear what you’re trying to do.
Please add details and examples.

Hello JD,

I am building a marketplace where people can advertise things for sale and what I would like to create is as follows.

After a user has logged in, on their account pages they will see a page where they can view their “live adverts”.

So what I need help with is the code for this.

I have a dataset that I created called dataset1 this dataset is the information about each item for sale. Within this, is a reference field linking to the Private Members information dataset.

Either in a table of a repeater, I need to show each individual what adverts they have for sale on the site. I thought I could do this by having a text field linked to the Private member dataset showing their login email address at the top of the page and then use this text box as a filter tool for a repeater to find the lines that use this email address. Does that make sense?

Step 1 - TEXT field - linked to PRIVATE MEMBERS DATABASE - displays the login email address from the user.

Step 2 - The repeater uses displayed email address to find it in DATASET B and only displays the lines (advert) that use that email address.

Please let me know if that doesn’t make sense.

Many thanks

Elliott

@reynoldselliott21 You don’t have to query the PrivateMemebersData collection in order to get the current user email. You can use .getEmail().
See here:
https://www.wix.com/corvid/reference/wix-users/user/getemail

Okay great , and then how would I use that to filter the repeater?

@reynoldselliott21 since you said the email field in collection B is of Type:reference, it’s actually contains the user ID.
So you should query the collection based on the user id and no need to use getEmail at all. something like:

import wixData from 'wix-data';
import wixUsers from 'wix-users';
let currentUser = wixUsers.currentUser, userId = currentUser.id;
$w.onReady(() => {
if(currentUser.loggedIn){
wixData.query("CollectionName")
.eq("email", userId)
.find()
.then(r => {
if(r.items.length > 0){
let userData = r.items[0];
$w("#userInfoTextElement").text = userData.liveAdverts;
}
})
}
})

Thanks JD will that code then show results and link directly to the repeater ?

@reynoldselliott21 No. You haven’t described your database structure, so I built it to show a single value in a single text element. If you want to use a repeater, further description will be needed.

Thank Jd, I want it to show similar to the repeater “featured artworks” on my home page that you helped me out with.

https://www.arttraderlimited.com/home-1

With most people it will only display one thing, however some might need multiple.

Is that difficult?

@reynoldselliott21 Please describe the collection schema. What fields do you have, is it a single row per user or many rows per user etc…

Thanks JD, It is all on one Row.

I have a 24 fields, mostly text, then a couple of imagery and some numbers and tags nothing crazy.

I have always just connected through the “link to data” button on a repeater and then coded the use for the repeater. I have a dynamic page already built.

Basically I will duplicate the repeater on the home page to put in this “see your adverts” section but just change the backend code?

It’s rally not clear. You can’t expect us to understand what’s going on from your description.
If it’s only one row, why are you using a repeater at all? It is a single item.

@jonatandor35 Sorry JD I thought you meant is each entry one line or multiple, See attached exactly how the dataset looks, this will obviously grow as more people upload.

@reynoldselliott21 Your screenshot is too blurry. Just explain in words.

Thank you JD

The Dataset is made up of the following fields.

Artwork Title- text
Title image - image
Artwork id - text
Type of art - text
Medium - text
Frame - text
Height - number
Width - number
Asking price - number
Coa - text
Condition- text
Photos - media gallery
Type of seller - text
Seller contact number - text
Seller email - text
Style of art - tags
Owner - reference (private member information dataset)

There are multiple rows and this will grow on a daily basis as more sellers submit their artworks to sell.

The repeater will be on a private members page “your current adverts” where they can view the adverts that they have submited to us, like on eBay, view your advert

Like the repeater is on my homepage “featured artworks” i would like to duplicate this but instead of randomising i want it to show their artworks they submitted to us. Sometimes it will be one artwork sometimes it will 10 and so on. I created this form using a template repeater, connecting the display elements to the dataset and button to the artwork dynamic page i created. Then using a code and module that you kindly gave me for the backend to randomize.

Fyi. Please note users do not write data to this database only me using the info they put on forms as it needs to be moderated by me.

@jonatandor35 would this work?

import wixData from ‘wix-data’ ;
import wixUsers from ‘wix-users’ ;
let currentUser = wixUsers.currentUser, userId = currentUser.id;
$w.onReady(() => {
if (currentUser.loggedIn){
wixData.query( “Artwork” )
.eq( “owner1” , userId)
.find()
.then(r => {
if (r.items.length > 0 ){
let userData = r.items[ 0 ];
$w( “#repeater1” ).data = userData.liveAdverts;
}). catch ((err) => {
console.log(err);
});
$w( “#repeater1” ).expand();
}
}
})
}

@reynoldselliott21 No. Unless the value in the liveAdverts field is an array of objects and each of the items has a unique _id.

Thank you @J. D.

with all of the above, do you know which avenue I could investigate further to make this work. Reallu struggling and would really appreciate the help

@reynoldselliott21 I’d help you, but you really didn’t provide the necessary info.
You posted lots of details about the collection fields but I can’t see there anything regarding the liveAdverts. So it’s just not clear. I can only vaguely guess what you’re trying to do but I don’t want to offer solutions based on guesses.

Can I ask what your guess is and tell you if thats what I mean?