Skip to content

Instantly share code, notes, and snippets.

@mikkokotila
Created August 4, 2019 21:02
Show Gist options
  • Save mikkokotila/6eceaebf4ee4e66cc509fb23efda0a35 to your computer and use it in GitHub Desktop.
Save mikkokotila/6eceaebf4ee4e66cc509fb23efda0a35 to your computer and use it in GitHub Desktop.
function csvImport(path_to_file) {
d3.csv(path_to_file).then(prepData);
function prepData(dataset) {
// create the columns
var keys = Object.keys(dataset[0])
var headers = []
keys.forEach(item => headers.push(Object({"title": item, "sTitle": item})));
// create the data
data = []
dataset.forEach(row => data.push(Object.values(row)));
// create the DataTables.js
$(document).ready(function() {
$('#example').DataTable( {
data: data,
columns: headers
// set any additional config here
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment