@material-table/exporters
Advanced tools
Comparing version 1.0.5 to 1.0.6
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,5 +10,10 @@ value: true | ||
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _filefy = require("filefy"); | ||
function ExportCsv(columns, data) { | ||
function ExportCsv(columns) { | ||
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
var filename = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'data'; | ||
@@ -16,6 +23,20 @@ var delimiter = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ','; | ||
try { | ||
var finalData = data; // Grab first item for data array, make sure it is also an array. | ||
// If it is an object, 'flatten' it into an array of strings. | ||
if (data.length && !Array.isArray(data[0])) { | ||
if ((0, _typeof2["default"])(data[0]) === 'object') { | ||
// Turn data into an array of string arrays, without the `tableData` prop | ||
finalData = data.map(function (_ref) { | ||
var tableData = _ref.tableData, | ||
row = (0, _objectWithoutProperties2["default"])(_ref, ["tableData"]); | ||
return Object.values(row); | ||
}); | ||
} | ||
} | ||
var builder = new _filefy.CsvBuilder(filename + '.csv'); | ||
builder.setDelimeter(delimiter).setColumns(columns.map(function (col) { | ||
return col.title; | ||
})).addRows(Array.from(data)).exportFile(); | ||
})).addRows(Array.from(finalData)).exportFile(); | ||
} catch (err) { | ||
@@ -22,0 +43,0 @@ console.error("error in ExportCsv : ".concat(err)); |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Helper export methods for @material-table/core", | ||
@@ -9,0 +9,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6742
83