diff --git a/src/components/LeaderboardTeamBattingTable.vue b/src/components/LeaderboardTeamBattingTable.vue index 4885dc2..fa19bde 100644 --- a/src/components/LeaderboardTeamBattingTable.vue +++ b/src/components/LeaderboardTeamBattingTable.vue @@ -5,33 +5,33 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + + @@ -117,7 +117,9 @@ export default { }, data() { return { - battingStats: [] as BattingStat[] + battingStats: [] as BattingStat[], + sortKey: 'team' as keyof BattingStat, + sortOrder: 1 } }, computed: { @@ -145,6 +147,25 @@ export default { const unsortedBattingStats: BattingStat[] = await fetchTeamBattingStatsBySeason(this.seasonNumber) this.battingStats = unsortedBattingStats.sort((s1, s2) => s2.team.sname < s1.team.sname ? 1 : -1) }, + sortBy(stat: keyof BattingStat): void { + this.setKey(stat) + + if (stat == 'team') { + this.battingStats.sort((s1, s2) => s2.team.sname < s1.team.sname ? this.sortOrder : -1 * this.sortOrder) + return + } + + this.battingStats.sort((s1, s2) => s2[stat] < s1[stat] ? -1 * this.sortOrder : this.sortOrder) + }, + setKey(stat: keyof BattingStat): void { + if (this.sortKey === stat) { + // if key currently selected, flip sort order + this.sortOrder *= -1 + } else { + this.sortKey = stat + this.sortOrder = 1 + } + }, calculateStrikeoutPercent(stat: BattingStat): string { if (!stat.pa) return 'N/A' return (stat.so * 100 / stat.pa).toFixed(1)
TeamPAABRH2B3BHRRBISBCSBBSOBAOBPSLGOPSwOBATeamPAABRH2B3BHRRBISBCSBBSOBAOBPSLGOPSwOBA K%BPHRBPFOBP1BBPLOGIDPHBPSACIBBBPHRBPFOBP1BBPLOGIDPHBPSACIBB