binaychandra commited on
Commit
5ad571f
·
1 Parent(s): e3662c2

adding logic for download

Browse files
Files changed (1) hide show
  1. templates/data.html +19 -17
templates/data.html CHANGED
@@ -93,23 +93,25 @@
93
 
94
  // Function to handle the table data download
95
  function downloadTableData() {
96
- const selectedTable = $('#table-dropdown').val();
97
- const fileName = selectedTable + '.csv';
98
- const filePath = '/referencefiles/' + fileName;
99
-
100
- // Create a temporary link element
101
- const link = document.createElement('a');
102
- link.href = filePath;
103
- link.download = fileName;
104
-
105
- // Append the link to the body
106
- document.body.appendChild(link);
107
-
108
- // Trigger the download by simulating a click
109
- link.click();
110
-
111
- // Remove the link from the document
112
- document.body.removeChild(link);
 
 
113
  }
114
 
115
  // ... rest of the existing code ...
 
93
 
94
  // Function to handle the table data download
95
  function downloadTableData() {
96
+ const selectedTable = $('#table-dropdown').val();
97
+ if (selectedTable) {
98
+ const fileName = `referencefiles/${selectedTable}.csv`;
99
+ fetch(fileName)
100
+ .then(response => response.blob())
101
+ .then(blob => {
102
+ const url = window.URL.createObjectURL(blob);
103
+ const a = document.createElement('a');
104
+ a.style.display = 'none';
105
+ a.href = url;
106
+ a.download = `${selectedTable}.csv`;
107
+ document.body.appendChild(a);
108
+ a.click();
109
+ window.URL.revokeObjectURL(url);
110
+ })
111
+ .catch(error => console.error('Error downloading the file:', error));
112
+ } else {
113
+ alert('Please select a table to download.');
114
+ }
115
  }
116
 
117
  // ... rest of the existing code ...