import Tabulator from 'tabulator-tables' import csv from 'parse-csv' const datasetColumns = [ { title: 'Title', field: 'title', sorter: 'string' }, { title: 'Images', field: 'images', sorter: 'number' }, { title: 'People', field: 'people', sorter: 'number' }, { title: 'Year', field: 'year', sorter: 'number' }, { title: 'Citations', field: 'citations', sorter: 'number' }, { title: 'Influenced', field: 'influenced', sorter: 'number' }, // { title: 'Origin', field: 'origin', sorter: 'string' }, ] function getColumns(payload) { if (payload.opt.match('datasets.csv')) { return datasetColumns } return (payload.fields || '').split(', ').map(field => { switch (field) { default: return { title: field, field: field.toLowerCase(), sorter: 'string' } } }) } export default function append(el, payload) { const columns = getColumns(payload) const table = new Tabulator(el, { height: '311px', layout: 'fitDataFill', placeholder: 'No Data Set', columns, }) // let path = payload.opt // console.log(path, columns) fetch(payload.opt, { mode: 'cors' }) .then(r => r.text()) .then(text => { const data = csv.toJSON(text, { headers: { included: true } }) console.log(data) table.setData(data) }) }