Created
April 26, 2013 03:09
-
-
Save zackdever/5464832 to your computer and use it in GitHub Desktop.
converts an html table to a csv string, and makes it available as a file download
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convertTableToCsv(tableSelector) { | |
return _.map($(tableSelector + ' tr'), function(row) { | |
return _.map($(row).find('th, td'), function(datum) { | |
return datum.textContent.replace(/,/g, ''); | |
}).join(','); | |
}).join('\n'); | |
} | |
// to download | |
var data = convertTableToCsv('#mytable'); | |
window.location='data:text/csv;charset=utf8,' + encodeURIComponent(data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment