Filtering a Dataset based on CurrentUser issues

Hi everyone,
I am new to Wix coding so please be gentle!
I have spent a day and a half looking through this site, code examples, YT videos and alike and no matter what I try I simply cannot make the code work :frowning:

The idea is that a user logs into the sports site, it then takes the CurrentUser details and passes them to the dataset on the Score page; which in turn should then only show them their scores.

The first issue (which others seem to have encountered) is when the page loads it shows all members scores before the filter is applied, as the filter is applied the scores then only show the current users scores (or would do if the filter worked).

import wixData from 'wix-data';
import wixUsers from 'wix-users';

export function page1_viewportEnter(event) {
 //Add your code for this event here: 
}

export function button5_click(event) {
 //Add your code for this event here: 
   $w.onReady(function () {

 let name = "No user"
 let user = wixUsers.currentUser;
 let userid = user.id
 let options = {

 "suppressAuth": true,
 "suppressHooks": true
  };
 // pull name out of PrivateMembersData (file created by default logon)
    console.log(userid)
    wixData.get("Members/PrivateMembersData",userid, options)
    .then( (results) => {
 let item = results;    
      name = item.name         // pull out the name (by field "name")
 //console.log(name)      // Debugging purposes 
 // Now we have the name, filter the DS based on this person
      $w("#MyScoresDS").setFilter(wixData.filter()
        .eq('Name',name)
        );
    })
    .catch( (err) => {
 let errorMsg = err;
      console.log(err);
    });
  }); 
}

On clicking the button the table the DS is attached too goes blank.

Any suggestions most welcome.

I’ve even stripped out the code and simply used the setFilter line with data I know is in the database and that still doesnt work, so I am assuming the filter isnt returning the right results, but do not know how to query the array or display it to see what it has returned :frowning:

Finally found the cause, within the filter I was calling “Name”, but within the DB it was referred to as “title” - noob error!

$w.onReady( function () {
Should be after your imports and before your export functions too.
https://www.wix.com/corvid/reference/$w.html#onReady

@givemeawhisky Appreciate your help, thanks :slight_smile: