guntrip / table-magic

Converts between CSV, HTML and Markdown. Has a little form editor and a preview.
http://stevecat.net/table-magic/
MIT License
423 stars 38 forks source link

Adding a download button #23

Closed mxchinegod closed 7 years ago

mxchinegod commented 7 years ago

Hey there! Great repo. I'm having fun implementing it into a django project I'm working on and I'd be happy to give full credit and a pull request for anything I end up achieving.

If I wanted to implement a download button to grab the current array as a csv and download as something like example_data.csv, how would you recommend I go about it?

I've tried adding my own function + button but it didn't work and I'm in sort of a superficial rush so some help from the designer might be helpful.

Thanks!

guntrip commented 7 years ago

Hi @DylanAlloy! Sorry to have taken a while to respond.

It looks like there might be a solution, for HTML 5 ready browsers, here on StackOverflow.

You could have a button on the CSV tab and pop the contents of the textarea into a function like the one described. As the user would already be on the CSV tab, all the conversion would already have been completed.

I'll take a shot at this right now!

guntrip commented 7 years ago

@DylanAlloy - this is implemented now. For your own project, you can see the new function here: https://github.com/stevecat/table-magic/blob/master/magic.js#L167

This just saves the current textarea but if your data is in another format, you could convert that to an array, using the revalant function, and then use array2csv() and pop that into the link's href.

Hope this is in time to be helpful! 😸