have a data base for a gallery on my dynamic page, but how do I filter this by user to show individual images from that user only
@Michael John Burgess
There are different ways you can do this. I’ll explain by connecting a dropdown to the users.
First, connect the dropdown list to your dataset that contains the members like the image below.
Then, on the properties panel, add an onChange to your dropdown. Then add the code below
import wixData from 'wix-data';
export function dropdown1_click(event, $w) {
//add this code inside your dropdown
$w("#dataset1").setFilter( wixData.filter()
.eq("name", $w("#dropdown1").value) //name - this is your database field key, replace with your own
);
Best of luck!
Tiaan
thanks ever so much, is there a way of doing this without a drop down box but with a link on a members page that take you to that members images
Off course…, you can simply create another dynamic page that shows only images related to a specific member, then add a button on the members page and link it to this second dynamic page through the dataset.
Simple as that, no code needed.
Tiaan
ok thanks… also if there a way to use the owner field to do this with in any way and how would I go about doing that with the dynamic page
I’m not sure I follow…?
well first how do I do what you suggested with the dynamic page… and when I connect the gallery to the database is there a way of using the owner field for the gallery and or url so that it picked up the member that uploaded it for the individual dynamic pages
The dynamic page will do the filtering for you…
thats what I am not understanding sorry, how does it do it and how do I set it up correctly without dropdown
I think we should back up a bit - how did you create your members section, using the WiX Members App or a custom coded members solution?
with the members wix app
Ok, then this would need a bit of a different approach. Somehow you will need to tie the images to the specific member, either through the userID or through the user’s email.
So, if you tie it to the user via his email, you will need to create an additional database column where you input the users’ email next to each image associated with him.
Then, remove any filters you have on the dynamic pages’ dataset for the images, and run the code below:
import wixUsers from 'wix-users';
import wixData from 'wix-data';
$w.onReady(function() {
let user = wixUsers.currentUser;
let userId = user.id; // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true
user.getEmail()
.then((email) => {
let userEmail = email;
$w("#myDataset").setFilter( wixData.filter() //update "myDataset" with your dataset's name
.eq("userEmail", email) //update "userEmail" with your database field key
);
});
});
This should do the trick.
Tiaan
Thanks ever so much but I have found a training guide online on how to create a social network with wix Building A Social Network in Wix | Part 2 | Planning and Creating Databases - YouTube
Awesome stuff