It is a very a lot wanted requirement in all most all internet purposes as and when backend would not assist obtain for given outcomes.
We usually populate ends in desk -> To populate we have to iterate over array accommodates information objects.
Like,
const information = [
{ name: 'Tom', id: '1234'},
{ name: 'James', id: '3456'},
{ name: 'Jerry', id: '7890'},
{ name: 'Peter', id: '4321'}
];
And, the above types desk as:
Simply need similar outcomes to be downloaded as CSV.
const headers = Object.keys(information[0]).be part of();
const content material = information.map(worth => Object.values(worth).be part of());
const csv = [headers].concat(content material).be part of("n");
const component = doc.createElement('a');
component.href = 'information:textual content/csv;charset=utf-8,' + encodeURI(csv);
component.goal = '_blank';
component.obtain = 'export.csv';
component.click on();
Carried out. Your CSV will get obtain as present in under:
At all times welcome any enhancements.
Thanks.
Comply with: https://twitter.com/urstrulyvishwak