Browse Source

Refactor code to dynamically generate the download filename based on the current date and time

node16
Onja 12 months ago
parent
commit
5c43e55e64
  1. 5
      src/assets/js/main.js

5
src/assets/js/main.js

@ -40,8 +40,11 @@ const sendRequest = (url, data) => {
const blob = new Blob([data], { type: 'text/csv' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
let date = new Date();
// format date to YYYY-MM-DD HH:MM
date = date.toISOString().slice(0, 16).replace('T', ' ');
a.href = url;
a.download = 'fichier.csv'; // Nom du fichier
a.download = `export-${date}.csv`; // Nom du fichier
document.body.appendChild(a);
// Cliquez sur le lien pour déclencher le téléchargement

Loading…
Cancel
Save