You can export the table as a CSV yourself , upload the file to the file manager, and add a link to it on your page. If you want it to be more dynamic and update automatically when the table is updated I don't believe there is any built in functionality for that. You could however use javascript to output the data into an array and create a csv download from that.
You can export the table as a CSV yourself , upload the file to the file manager, and add a link to it on your page. If you want it to be more dynamic and update automatically when the table is updated I don't believe there is any built in functionality for that. You could however use javascript to output the data into an array and create a csv download from that.
Script to let user download a specific table from Hubdb
lösung
Hi Alyssa,
As much as I tried, nothing seemed to work in regards of outputting HubDB data into a javascript array. I tried to use your solution with the stackoverflow way to generate csv. But nothing works. Would you mind give me an example of how you would do the conversion? just a simple example will help me come up with a solution.
Script to let user download a specific table from Hubdb
lösung
<a href="" download="hubdb_table.csv" id="download-link">Download CSV</a>
<script>
$( document ).ready(function() {
{% set data = hubdb_table_rows(XXXXXX).objects %}
{% set columns = hubdb_table(XXXXXX).columns %}
const rows = [
[
{% for column in columns %}{{ column.name|tojson }},{% endfor %}
],
{% for item in data %}
[
{% for column in columns %}
{{ item[column.name]|tojson }},
{% endfor %}
],
{% endfor %}
];
let csvContent = "data:text/csv;charset=utf-8,";
rows.forEach(function(rowArray) {
let row = rowArray.join(",");
csvContent += row + "\r\n";
});
var encodedUri = encodeURI(csvContent);
var link = $('#download-link');
link.attr("href", encodedUri);
});
</script>
Replace XXXXXX with your HubDB table's ID and if using this in a custom module the script will need to be in the HTML/HubL frame since the Javascript frame doesn't allow the use of HubL.
If this answer solved your question, please mark it as the solution.