Hi
I need to have a button in my site that downloads the filtered data from a dataset.
How can i do it?
Also, how can i get the current logged in user’s name (from crm or contacts)?
Hey
You can create a file from data collection and make that downloadable I guess using the HTML Component but you can’t get the users name from crm or contacts at this point. What format should you prefer in the file?
Csv or Excel.
Ok, so there is a small trick to make that happen and you will need to be good in string manipulation in Javascript.
<a href="data:application/octet-stream,field1%2Cfield2%0Afoo%2Cbar%0Agoo%2Cgai%0A">CSV Octet</a>
If you create that link for a user, clicking it will prompt them to download the file and it will be a CSB formatted one.
First the field headers and then all the data. Understand?
And if you want to set the filename of the file they download just att the download attribute and the filename as below.
<a href="data:application/octet-stream,field1%2Cfield2%0Afoo%2Cbar%0Agoo%2Cgai%0Av" download="file.csv">CSV with filename</a>
You can even make support of downloading JSON formatted files using this technique though it is harder to format.
<a href="data:application/octet-stream, {'menu': { 'id': 'file', 'value': 'File', 'popup': { 'menuitem': [ {'value': 'New', 'onclick': 'CreateNewDoc()'}, {'value': 'Open', 'onclick': 'OpenDoc()'}, {'value': 'Close', 'onclick': 'CloseDoc()'} ] } }}" download="file.json">JSON with filename</a>
Ok. You create the file here and download it. But i have the data already in a dataset. I just need to download it.