Skip to content

Commit

Permalink
Add download feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-strange committed Jul 8, 2024
1 parent 4c4f9e9 commit 26418cc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/assets/js/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,21 @@ function updateRow(button) {

updateTable();
}

function downloadCSV() {
let csv = 'Shirt Number,Total Assists,Total Goals,Total Blocks/Interceptions\n';

for (const player in playerStats) {
csv += `${player},${playerStats[player].assists},${playerStats[player].goals},${playerStats[player].blocks}\n`;
}

const blob = new Blob([csv], { type: 'text/csv' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.setAttribute('hidden', '');
a.setAttribute('href', url);
a.setAttribute('download', 'player_stats.csv');
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
1 change: 1 addition & 0 deletions src/index.vto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ title: Fris Stats
</div>

<h2>Player Stats Table</h2>
<button onclick="downloadCSV()">Download as CSV</button>
<table id="statsTable">
<thead>
<tr>
Expand Down

0 comments on commit 26418cc

Please sign in to comment.