Spaces:
Running
Running
Commit
·
e3662c2
1
Parent(s):
08f529a
another implementation of download functionality
Browse files- templates/data.html +16 -21
templates/data.html
CHANGED
|
@@ -93,28 +93,23 @@
|
|
| 93 |
|
| 94 |
// Function to handle the table data download
|
| 95 |
function downloadTableData() {
|
| 96 |
-
const
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
let csvContent = '';
|
| 100 |
-
|
| 101 |
-
rows.forEach(row => {
|
| 102 |
-
const cols = row.querySelectorAll('td, th');
|
| 103 |
-
const rowData = Array.from(cols).map(col => col.innerText).join(',');
|
| 104 |
-
csvContent += rowData + '\n';
|
| 105 |
-
});
|
| 106 |
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
|
|
|
|
|
|
| 118 |
}
|
| 119 |
|
| 120 |
// ... rest of the existing code ...
|
|
|
|
| 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 ...
|