binaychandra commited on
Commit
e3662c2
·
1 Parent(s): 08f529a

another implementation of download functionality

Browse files
Files changed (1) hide show
  1. 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 table = document.querySelector('.tabcontent:visible table');
97
- if (table) {
98
- const rows = table.querySelectorAll('tr');
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
- const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
108
- const link = document.createElement('a');
109
- link.href = URL.createObjectURL(blob);
110
- link.download = 'table_data.csv';
111
- link.style.display = 'none';
112
- document.body.appendChild(link);
113
- link.click();
114
- document.body.removeChild(link);
115
- } else {
116
- alert('No table data available to download.');
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 ...