Would be a neat feature, could see it work well in cloud with editing lookup tables, but there are some other ways we want to make those work better. In the meantime if anyone needs this now, here's some code to do it. This mechanism can be used for other file types as well. This code requires a custom html field that calls the function outlined below.
HTML:
<button class="btn btn-default" onclick="onDLClick()">Download</button>
JS:
// Set to your fields needed to generate the table
const fields = {
downloadButton: { fieldId: 13 },
table: { fieldId: 8 },
}
const getCSVFromTable = () => {
// Dont actually use this to generate your csv. This is just a quick and dirty example
const tableValues = LFForm.getFieldValues(fields.table);
let csvText = `col1, col2\n`;
for (const row of tableValues) {
csvText += Object.values(row).slice(0, -2).map(c => c.data).join(',') + '\n';
}
// Must return b64 encoded string generated here
return btoa(csvText);
}
window.onDLClick =async () => {
// If your generation is slow this makes sense, otherwise its too quick to notice
await LFForm.changeFieldSettings(fields.downloadButton, {
content: `<button class="btn btn-default" disabled>Preparing...</button>`
});
const csv = getCSVFromTable();
const b64 = `data:text/csv;base64,${csv}`;
// Downloading requires another click by the user due to browser security
await LFForm.changeFieldSettings(fields.downloadButton, {
content: `<a class="btn btn-default" href="${b64}" download="customname.csv">Download</a>`
});
}