Last active
June 16, 2021 09:52
-
-
Save Cloud-Awesome/6bb2c0ef0e5d05c743f71160189e0ceb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[...] | |
<div id="csv_data"></div> | |
<script type="text/javascript"> | |
// '/odata-web-pages' is where I published the sample FetchXml-generated feed | |
fetch("/odata-web-pages?website-id={{ request.params['website-id'] }}") | |
.then(response => response.json()) | |
.then((data) => { | |
const link = document.createElement("a"); | |
const linkText = "Download Csv file"; | |
let csvContent = "data:text/csv;charset=utf-8," + encodeURIComponent(data.map(e => e.join(",")).join("\n")) | |
link.append(linkText); | |
link.setAttribute("href", csvContent); | |
link.setAttribute("download", "your_csv_data_file.csv"); | |
link.setAttribute("title", "WebPage CSV Download"); | |
$("#csv_data").append(link); | |
}) | |
.catch((error) => { | |
console.error('Do something with this error:', error); | |
}); | |
</script> | |
[...] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated line 13 to encodeURIComponent CSV content. This handles special characters such as # which prevented full download