diff --git a/packages/react-bootstrap-table2/src/body.js b/packages/react-bootstrap-table2/src/body.js index 9b69cb92f..33a8c18d7 100644 --- a/packages/react-bootstrap-table2/src/body.js +++ b/packages/react-bootstrap-table2/src/body.js @@ -1,6 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; +import _ from './utils'; import Row from './row'; const Body = ({ columns, data, keyField }) => ( @@ -8,7 +9,7 @@ const Body = ({ columns, data, keyField }) => ( { data.map((row, index) => ( { - let content = row[column.dataField]; + let content = _.get(row, column.dataField); if (column.formatter) { content = column.formatter(content, row, rowIndex, column.formatExtraData); } diff --git a/packages/react-bootstrap-table2/src/row.js b/packages/react-bootstrap-table2/src/row.js index 94a0aba91..fdaad044d 100644 --- a/packages/react-bootstrap-table2/src/row.js +++ b/packages/react-bootstrap-table2/src/row.js @@ -1,6 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; +import _ from './utils'; import Cell from './cell'; const Row = ({ row, rowIndex, columns }) => ( @@ -9,7 +10,7 @@ const Row = ({ row, rowIndex, columns }) => ( columns.map(column => ( curr[path], target); + } catch (e) {} + return result; +} + +export default { + get +}; diff --git a/packages/react-bootstrap-table2/test/utils.test.js b/packages/react-bootstrap-table2/test/utils.test.js new file mode 100644 index 000000000..feb33e937 --- /dev/null +++ b/packages/react-bootstrap-table2/test/utils.test.js @@ -0,0 +1,24 @@ +import _ from '../src/utils'; + +describe('Utils', () => { + describe('get', () => { + const data = { + name: 'A', + address: { + road: 'BCD', + postal: '1234-12345', + city: { + name: 'B' + } + } + }; + + it('should return correct data', () => { + expect(_.get(data, 'name')).toEqual(data.name); + expect(_.get(data, 'address.road')).toEqual(data.address.road); + expect(_.get(data, 'address.city.name')).toEqual(data.address.city.name); + expect(_.get(data, 'address.notExist')).toEqual(undefined); + expect(_.get(data, 'address.not.exist')).toEqual(undefined); + }); + }); +});