Filtering repeaters on dynamic page using tags for individual members data only

Hello, I have a dynamic page that is built for individual sport team coaches to view their individual roster of athletes which are filtered and tagged by the Organization Name. The dynamic page is connected to the main Coaches information dataset and the remaining datasets are all connected to the players information dataset.

I also have repeaters connected to this page, showing the main roster of their athletes, and then other repeaters that show a certain stat or metric from the player like how fast each player ran and which ran the fastest so he coach can have a leaderboard too.

I am trying to filter the list of athletes using tags and filter by their graduation year. Once the graduation tag is selected the repeaters should all only show those players within that coaches organization with that selected graduation year. I have tried this on a main wix page and it works just fine, but when I try this on my dynamic page, using the same code, it does not work and displays all the athletes in the entire database from all teams instead of only showing the coach his/her unique list of athletes filtered by their organization name. It does filter by grad year, but shows all athletes from all teams. Then when you deselect the graduation year tag, the repeater then displays every athlete from all teams again but now from all graduation years. I want the repeaters to only show the coach his/her athletes all the time, not all players from other teams please.

What do I need to add to my code below to allow for the repeaters to only show the athletes associated to their own individual team name and not show all athletes from all teams?

Thank you!

$w . onReady ( function () {

$w ( '#selectionTags1' ). onChange (() => { 
    const  selectedTag  =  $w ( '#selectionTags1' ). value ; 

    let  filter  =  wixData . filter (); 

    if  ( selectedTag . length  >  0 ) { 
        filter  =  filter . hasSome ( "gradYear" ,  selectedTag ); 
    } 

    $w ( '#dataset1' ). setFilter ( filter ); 
    $w ( '#dataset2' ). setFilter ( filter ); 
    $w ( '#dataset3' ). setFilter ( filter ); 
    $w ( '#dataset5' ). setFilter ( filter ); 
    $w ( '#dataset6' ). setFilter ( filter ); 
    $w ( '#dataset7' ). setFilter ( filter ); 
    $w ( '#dataset8' ). setFilter ( filter ); 
    $w ( '#dataset9' ). setFilter ( filter ); 
    $w ( '#dataset10' ). setFilter ( filter ); 
    $w ( '#dataset11' ). setFilter ( filter ); 

}) 

});

What are all those datasets? Why all of them have the same filter?

No sir, they have separate filters for each repeater that’s on the page to filter each sports activity. Example- one filter for the 60 yard run time, another filter dedicated to another repeater that shows the ball speed and etc. If there is a way to not have as many datasets connected, please let me know. Thank you!

I’m trying to do some similars things and have some solutions. Just to clarify, are you filter the info (players) they can see based off the current logged in Coach or just whatever coach you select from the larger dynamics page?

Can you show me your data collection so I can see what is going on… I’m pretty sure that many datasets in a page is not an optimal approach to the data.

Hello @bwprado I am fairly new to developing and coding so I apologize. How would I show you my collection? is it a URL I share with you? Thank you for your help here.

Hello Caleb, the dynamic page is designed to give access to only the individual coach. The coach signs up and is given a unique ID and the page opens and filters based on the coaches ID. Then this way, he/she sees only their players tagged through their organization name. Does this make sense? Thank you.

@info13177 Yeah, absolutely. I was doing a similar thing using this code filtering role ID:

import wixData from 'wix-data';
import { currentMember } from 'wix-members';

$w.onReady(function () {

const roleIds = []; // to store the role(s)

currentMember.getRoles()
  .then((roles) => {
    roles.forEach((role) => {
        roleIds.push(role._id);
    })
    console.log(roleIds); // this is to double-check I'm getting
    // this filters the data depending on user roles
        $w("#dynamicDataset").setFilter(wixData.filter()
        .hasSome('role', roleIds)
        );
    return roleIds;
  })
  .catch((error) => {
    console.error(error);
  })

});

Doing it this way you do have to add the Role ID wix gives you into the data collection manually and associate it with the data you want it to show them.

Also, I’ve found trying to hard code filters AND using the filters within the UI doesn’t work well. (just my experience)

@caleb-mcfarland Thank you sir!