fixes csv export
This commit is contained in:
parent
2a292f2006
commit
4b3e2171e9
|
@ -42,45 +42,47 @@ export default {
|
|||
|
||||
setup() {
|
||||
const store = dataDisplayStore()
|
||||
|
||||
const xs_screen = inject("xs_screen")
|
||||
|
||||
function generateCSV() {
|
||||
var columns = []
|
||||
let field_index = store.field_index
|
||||
|
||||
field_index.forEach((field, i) => {
|
||||
columns.push(field.label)
|
||||
});
|
||||
const stringifier = stringify({ header: true, columns: columns });
|
||||
var data = []
|
||||
store.itemsToDisplay.forEach((row, i) => {
|
||||
var values = []
|
||||
field_index.forEach((field, i) => {
|
||||
var values = {}
|
||||
store.field_index.forEach((field, i) => {
|
||||
let col_label = field.label
|
||||
|
||||
if (field.name == 'marked') {
|
||||
values.push(store.getFormattedValue({field_name: 'marked', field_value: row.marked}))
|
||||
} else if (field.name == 'created') {
|
||||
values.push(store.getFormattedValue({field_name: 'created', field_value: row.created}))
|
||||
} else if (row.data[field.name] !== undefined) {
|
||||
values[col_label] = store.getFormattedValue({field_name: 'marked', field_value: row.marked})
|
||||
}
|
||||
else if (field.name == 'created') {
|
||||
values[col_label] = store.getFormattedValue({field_name: 'created', field_value: row.created})
|
||||
}
|
||||
else if (row.data[field.name] !== undefined) {
|
||||
var field_value = row.data[field.name]
|
||||
if (field.name.endsWith('__html')) {
|
||||
field_value = row.data[field.name].value
|
||||
}
|
||||
let _field = {'field_name': field.name,
|
||||
'field_value': field_value}
|
||||
values.push(store.getFormattedValue(_field))
|
||||
} else {
|
||||
values.push("Empty")
|
||||
'field_value': field_value}
|
||||
values[col_label] = store.getFormattedValue(_field)
|
||||
}
|
||||
else {
|
||||
values[col_label] = ""
|
||||
}
|
||||
})
|
||||
stringifier.write(values);
|
||||
data.push(values)
|
||||
});
|
||||
let result = stringifier.read().toString()
|
||||
let blob = new Blob([result], {type: "text/csv;charset=utf-8"});
|
||||
var title = store.meta.title + ".csv"
|
||||
if (store.data_type == 'user') {
|
||||
title = "users.csv"
|
||||
}
|
||||
saveAs(blob, title);
|
||||
stringify(data, {
|
||||
header: true
|
||||
},
|
||||
function (err, output) {
|
||||
let blob = new Blob([output], {type: "text/csv;charset=utf-8"});
|
||||
var title = store.meta.title + ".csv"
|
||||
if (store.data_type == 'user') {
|
||||
title = "users.csv"
|
||||
}
|
||||
saveAs(blob, title);
|
||||
})
|
||||
}
|
||||
|
||||
function generateJSON() {
|
||||
|
|
Loading…
Reference in a new issue