From 5c43e55e64fd08b0d4c0f559ace6d2aaa4fa79d2 Mon Sep 17 00:00:00 2001 From: Onja Date: Wed, 11 Oct 2023 11:38:40 +0300 Subject: [PATCH] Refactor code to dynamically generate the download filename based on the current date and time --- src/assets/js/main.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/assets/js/main.js b/src/assets/js/main.js index 12bef7c..4cee174 100644 --- a/src/assets/js/main.js +++ b/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