| 1 |
"use strict"; |
| 2 |
(function ($) { |
| 3 |
$(window).on('elementor:init', () => { |
| 4 |
elementor.hooks.addAction('panel/open_editor/widget/king-addons-data-table', (panel, model, view) => { |
| 5 |
elementor.channels.editor.on('king-addons-data-table-export', () => { |
| 6 |
|
| 7 |
// Retrieve all table rows |
| 8 |
const rows = view.$el.find('.king-addons-data-table .king-addons-table-row'); |
| 9 |
const data = []; |
| 10 |
|
| 11 |
// Iterate over each row and collect text from relevant cells |
| 12 |
rows.each((_, row) => { |
| 13 |
const cols = row.querySelectorAll('.king-addons-table-text'); |
| 14 |
const rowData = Array.from(cols, col => col.innerText).join(','); |
| 15 |
data.push(rowData); |
| 16 |
}); |
| 17 |
|
| 18 |
// Construct CSV content from array of rows |
| 19 |
const csvContent = data.join('\n'); |
| 20 |
|
| 21 |
// Create a Blob from CSV data and generate a download link |
| 22 |
const blob = new Blob([csvContent], { type: 'text/csv' }); |
| 23 |
const downloadLink = document.createElement('a'); |
| 24 |
downloadLink.download = 'placeholder.csv'; |
| 25 |
downloadLink.href = URL.createObjectURL(blob); |
| 26 |
downloadLink.style.display = 'none'; |
| 27 |
|
| 28 |
// Append link to DOM, trigger download, and then remove the link |
| 29 |
document.body.appendChild(downloadLink); |
| 30 |
downloadLink.click(); |
| 31 |
document.body.removeChild(downloadLink); |
| 32 |
URL.revokeObjectURL(downloadLink.href); |
| 33 |
}); |
| 34 |
}); |
| 35 |
}); |
| 36 |
})(jQuery); |