diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-12-16 16:29:04 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-12-16 16:29:04 +0100 |
| commit | 05fc975a313aa38483d904cb9ad07a029641d086 (patch) | |
| tree | 85f3d4fdf3688c2779d3ca3ba9c59910a48d1df9 /client/tables.js | |
| parent | 110f3a34f1f36d0ea999d4aa34bbe66d5f2a01da (diff) | |
rebuild
Diffstat (limited to 'client/tables.js')
| -rw-r--r-- | client/tables.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/client/tables.js b/client/tables.js new file mode 100644 index 00000000..6b00bbde --- /dev/null +++ b/client/tables.js @@ -0,0 +1,43 @@ +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) + }) +} |
