using json-2-csv package for the csv export now since the old package has not been updated in 4 years
This commit is contained in:
parent
eb5fd127e3
commit
cf559d48a2
4 changed files with 64 additions and 23 deletions
|
|
@ -93,14 +93,11 @@ class ExportDataSettings extends React.Component<Props, State> {
|
|||
};
|
||||
|
||||
submit = () => {
|
||||
console.log("submit export request")
|
||||
const { device, component, newMeasurements, user } = this.props;
|
||||
const { startDate, endDate } = this.state;
|
||||
const { sampleMeasurements, listUnitMeasurements } = this.context;
|
||||
|
||||
this.setState({ isLoading: true });
|
||||
console.log("Device")
|
||||
console.log(device)
|
||||
// if (newMeasurements) {
|
||||
listUnitMeasurements(
|
||||
device.id(),
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
// import * as save from "save-svg-as-png";
|
||||
// import * as jsonexport from "jsonexport";
|
||||
import { or } from "./types";
|
||||
// const jsonexport = require("jsonexport");
|
||||
// const save = require("save-svg-as-png")
|
||||
import { json2csv } from 'json-2-csv';
|
||||
|
||||
export function saveSVG(element: string, filename: string, options: Object) {
|
||||
// save.saveSvgAsPng(document.getElementById(element), filename, options);
|
||||
|
|
@ -52,25 +51,25 @@ export function exportDataToCSV(filename: string, data: Array<any>) {
|
|||
return;
|
||||
}
|
||||
|
||||
// jsonexport(data, function(err: any, csv: any) {
|
||||
// if (err) return console.log(err);
|
||||
// var blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
|
||||
// var link = document.createElement("a");
|
||||
// link.href = window.URL.createObjectURL(blob);
|
||||
// link.download = or(filename, "generated") + ".csv";
|
||||
// document.body.appendChild(link);
|
||||
// link.click();
|
||||
// setTimeout(function() {
|
||||
// document.body.removeChild(link);
|
||||
// window.URL.revokeObjectURL(link.href);
|
||||
// }, 100);
|
||||
// });
|
||||
let csv = json2csv(data)
|
||||
//console.log(csv)
|
||||
var blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
|
||||
var link = document.createElement("a");
|
||||
link.href = window.URL.createObjectURL(blob);
|
||||
link.download = or(filename, "generated") + ".csv";
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
setTimeout(function() {
|
||||
document.body.removeChild(link);
|
||||
window.URL.revokeObjectURL(link.href);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
export function exportJSON(filename: string, data: Array<any>) {
|
||||
if (!data || !data.length) {
|
||||
return;
|
||||
}
|
||||
//deprecated function
|
||||
// export function exportJSON(filename: string, data: Array<any>) {
|
||||
// if (!data || !data.length) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// jsonexport(data, function(err: any, csv: any) {
|
||||
// if (err) return console.log(err);
|
||||
|
|
@ -85,4 +84,4 @@ export function exportJSON(filename: string, data: Array<any>) {
|
|||
// window.URL.revokeObjectURL(link.href);
|
||||
// }, 100);
|
||||
// });
|
||||
}
|
||||
//}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue