Filtering a table based on member ID on a dynamic page

Hi there,

I’m trying to create a table on dynamic pages which filter automatically based on the current user.

I have two databases:

  1. privatememberdata: data are created automatically when a user sign up as a site member. The dynamic pages are created based on privatememberdata database so only site member can see the details.

  2. project(“projectdataset”) : database contains member ID (which match with the _ID in privatememberdata database) and other project info (e.g. status etc.) The project data are specific to each site member.

My objective is to use the member ID to create the connection between two datasets and use the member ID to filter the project information so each site member can only see their own project info when they are logged in.

I have tried the following code but with no luck.

Any advice or help would be really appreciated. Please feel free to let me know if you need more information to answer the question.

Thanks in advance!

How does your DATABASE (which is connected to “projectdataset”) look like?
Example-Screenshot?

See attached screenshots of “projectdatase”.

The Order No field is a reference field to Order dataset (wiz store).
The Email filed is a reference field to private member dataset.

Thanks!

I do not know if this works, or will help you.
It is a 5-min-solution (not tested)!

import wixdata from 'wix-data';
import wixdusers from 'wix-users';

$w.onReady(()=>{
    $w('#projectdataset').onReady(()=>{
        const userID = wixusers.CurrentUser.id;
        console.log(userID)
        $w('#projectdataset').setFilter(wixdata.filter().eq("memberId", userID)
        .then((res)=>{
           console.log(res)
        })
    })
})

Do you get any RESULTS (res) in CONSOLE ?

And next time, please use a CODE-TAG instead of an image to show your code. Do not like to retype all the code, from an image. :grin:

Will be back soon…

@russian-dima Thanks for the response. I managed to filter the table by member ID now. It turns out to be a site permission issue. The code was fine.

However, I do noticed that there is a lag of site filtering the table. When a user logged in, he can see the whole dataset for a sec and then the filter start to kick in and he can only see the projects specific for him. Do you know if there is a way to avoid this lagging issue?

Thank you!

@printerior2020
Surely the most simple solution would be first set the table as “hidden” and when all the filter has loaded, you could show the table again.

@printerior2020 I think the only way to do that is to move off of the UI created dynamic dataset and use $w.data only. I’m at this point now and was thinking the issue you describe would be what happens (you see the full data set first and it would take time because you’re setting a new filter).

The choices are, as far as I can tell, move everything to $w.data or accept the longer load time and full list flash. I cannot move my page under members because I have an order number field to the page. It’s frustrating that we can’t just filter, via the UI dataset, by member. If you figured out something better, please do share.

@shannon34563 , how did you go with this? Did you manage to find a solution by moving everything to $w.data or a workaround to the full list flash issue?

I’m just about to embark on creating something similar and I’m not sure which direction to take :thinking:

@sam35410 I have to go back and figure out the context and then I’ll get back to you. May be a day.

@sam35410 It looks like I didn’t actually end up solving this. I just moved the dynamic page under the “Wix Members Area” and then used wixUsers.currentUser.id. I hope that helps and sorry I didn’t resolve the original question. I think I just couldn’t figure out how to capture the current user ID outside of the Wix Members Area.