28 Posts
claudioalfonso
1 year ago
1
Topic

Hello

I'm not posting a doubt, but a solution: exporting search data to csv. 1. Create custom html module 2. Insert in highlighted code 3. Publish the module on the search page in a position at the end of the search

----- code

<script>

function exportTableToCSV(filename) {

var csv = [];

var rows = document.querySelectorAll("table tr");

for (var i = 0; i < rows.length; i++) {

var row = [], cols = rows[i].querySelectorAll("td, th");

for (var j = 0; j < cols.length; j++)

row.push(cols[j].innerText);

csv.push(row.join(","));

}

// Download CSV file

downloadCSV(csv.join("\n"), filename);

}

function downloadCSV(csv, filename) {

var csvFile;

var downloadLink;

// CSV file

csvFile = new Blob([csv], {type: "text/csv"});

// Download link

downloadLink = document.createElement("a");

// File name

downloadLink.download = filename;

// Create a link to the file

downloadLink.href = window.URL.createObjectURL(csvFile);

// Hide download link

downloadLink.style.display = "none";

// Add the link to DOM

document.body.appendChild(downloadLink);

// Click download link

downloadLink.click();

}

</script>

<button onclick="exportTableToCSV('SinDab_query.csv')">Baixar planilha de resultados</button>

Get a VIP membership
151 Posts
jimenaes
1 year ago
0
Level 1

Hi, claudioalfonso, thanks for sharing this. The custom html module is a normal  joomla module, right? The code you wrote goes in that html module, right?

Could you please explain what you mean by "2. Insert in highlighted code 3"?

Thanks again

Get a Book for SEBLOD