External Data Source for Custom Filter

External Data Source for Custom Filter

zgoforthzgoforth Posts: 493Questions: 98Answers: 2

Link to test case: https://jsfiddle.net/BeerusDev/n06greay/33/

Description of problem:

Hello,

I have the data object populating to the table and I am using rowGroup to group by Team. I have an external data source that isn't populating to the table, but I want to use it to help create a certain filter. I have another variable currentUser which in my actual application is a dynamic value. In this case, the current user is "Player 6", and in the teamData Player 6 is in "Team 2". So I would want the filter to only show results of trainings for Team 2.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,276Questions: 26Answers: 4,765
    Answer ✓

    I have another variable currentUser which in my actual application is a dynamic value.

    When you set currentUser to a value, Player 6 for example, you will need to loop through teamData to find the team number then set a variable, currentTeam for example that is used in the search plugin to filter the rows. See this example:
    https://jsfiddle.net/1f9tqday/

    Since its a Javascript exercise I'll leave it to you to write the code in getTeam() to loop through your data structure. Currently its hard codes to return Team 2.

    Kevin

  • zgoforthzgoforth Posts: 493Questions: 98Answers: 2

    @kthorngren thanks for your input, I ended up with the following:

    function getTeam() {
    
    const team = teamData
      .find(team => team.Players.includes(currentUser));
        return team.Team;
    }
    
    var currentUser = "Player 6";
    var currentTeam = getTeam(currentUser)
    
    

    Fiddle: https://jsfiddle.net/BeerusDev/yebonhL7/36/

Sign In or Register to comment.