Skip to content
Snippets Groups Projects
Commit bc07164e authored by Remi  PLANEL's avatar Remi PLANEL
Browse files

composable to downolad json object as csv

parent 7b6c8ed3
No related branches found
No related tags found
2 merge requests!140Draft: Download db results,!134Resolve "Table with all PDB files, to make them available to download"
Pipeline #118098 passed with stages
in 6 minutes and 45 seconds
import { ref } from 'vue';
import Papa from 'papaparse';
export default function useCsvDownload() {
const downloadCsv = (data: Record<string, any>[], fileName: string): void => {
const csvContent = Papa.unparse(data);
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
const link = document.createElement('a');
if (link.download !== undefined) {
const url = URL.createObjectURL(blob);
link.setAttribute('href', url);
link.setAttribute('download', fileName);
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
};
return {
downloadCsv,
};
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment