summaryrefslogtreecommitdiff
path: root/client/tables.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/tables.js')
-rw-r--r--client/tables.js43
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)
+ })
+}