From 61e3ef40879c05c7036ec5dd4c7710d4e5296b37 Mon Sep 17 00:00:00 2001 From: werther Date: Mon, 12 Sep 2022 11:32:46 +0200 Subject: [PATCH] removed dependency for json2Csv by accessing Json2CSVAsyncParser directly. See https://github.com/zemirco/json2csv/issues/539 --- src/datatable/InfineonDatatable.vue | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/datatable/InfineonDatatable.vue b/src/datatable/InfineonDatatable.vue index c0a137c..29c0050 100644 --- a/src/datatable/InfineonDatatable.vue +++ b/src/datatable/InfineonDatatable.vue @@ -110,7 +110,7 @@ import { toRefs, computed, ref, onMounted, watch, } from 'vue'; -import json2Csv from 'json2csv'; +import JSON2CSVAsyncParser from 'json2csv/lib/JSON2CSVAsyncParser'; import DatatableRow from './InfineonDatatableRow.vue'; import DatatablePager from './InfineonDatatablePager.vue'; import DatatableSortIcon from './InfineonDatatableSortIcon.vue'; @@ -249,7 +249,21 @@ async function exportCSV() { const opts = { fields, transforms }; - json2Csv.parseAsync(data.value, opts) + const parseAsync = async () => { + try { + const asyncParser = new JSON2CSVAsyncParser(opts); + const promise = asyncParser.promise(); + + data.value.forEach((item) => asyncParser.input.push(item)); + asyncParser.input.push(null); + + return promise; + } catch (err) { + return Promise.reject(err); + } + }; + + parseAsync() .then((csv) => { const sep = 'sep=,\r\n'; const BOM = new Uint8Array([0xEF, 0xBB, 0xBF]);