Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Added nested object key access for data and column match #165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion dist/ExcelPlugin/components/ExcelFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ var _tempaXlsx = require("tempa-xlsx");

var _tempaXlsx2 = _interopRequireDefault(_tempaXlsx);

var _lodash = require("lodash");

var _lodash2 = _interopRequireDefault(_lodash);

var _ExcelSheet = require("../elements/ExcelSheet");

var _ExcelSheet2 = _interopRequireDefault(_ExcelSheet);
Expand Down Expand Up @@ -68,7 +72,7 @@ var ExcelFile = function (_React$Component) {

_react2.default.Children.forEach(columns, function (column) {
var getValue = typeof column.props.value === 'function' ? column.props.value : function (row) {
return row[column.props.value];
return _lodash2.default.get(row, column.props.value);
};
var itemValue = getValue(row);
sheetRow.push(isNaN(itemValue) ? itemValue || '' : itemValue);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"husky": "0.15.0-rc.13",
"jest": "^23.6.0",
"jest-environment-node": "22.4.1",
"lodash": "^4.17.21",
"nyc": "11.2.1",
"prop-types": "15.6.0",
"react": "16.0.0",
Expand Down
3 changes: 2 additions & 1 deletion src/ExcelPlugin/components/ExcelFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import PropTypes from "prop-types";
import {saveAs} from "file-saver";
import XLSX from "tempa-xlsx";
import _ from 'lodash';

import ExcelSheet from "../elements/ExcelSheet";
import {strToArrBuffer, excelSheetFromAoA, excelSheetFromDataSet} from "../utils/DataUtil";
Expand Down Expand Up @@ -52,7 +53,7 @@ class ExcelFile extends React.Component {
const sheetRow = [];

React.Children.forEach(columns, column => {
const getValue = typeof (column.props.value) === 'function' ? column.props.value : row => row[column.props.value];
const getValue = typeof (column.props.value) === 'function' ? column.props.value : row => _.get(row, column.props.value);
const itemValue = getValue(row);
sheetRow.push(isNaN(itemValue) ? (itemValue || '') : itemValue);
});
Expand Down