From 1176e690315c12ebf75bed41056f9eaab4c2126a Mon Sep 17 00:00:00 2001 From: Jan Christoph Bernack Date: Mon, 23 Oct 2017 16:36:14 +0200 Subject: [PATCH 1/5] Add dependency on lodash.get --- package.json | 1 + yarn.lock | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/package.json b/package.json index a848ee8e3..52d58ec4c 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ }, "dependencies": { "classnames": "^2.1.2", + "lodash.get": "^4.4.2", "prop-types": "^15.5.10", "react-modal": "^3.0.3", "react-s-alert": "^1.3.0" diff --git a/yarn.lock b/yarn.lock index 77c9514fa..6ab754832 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4646,6 +4646,10 @@ lodash.escape@~2.4.1: lodash._reunescapedhtml "~2.4.1" lodash.keys "~2.4.1" +lodash.get@^4.4.2: + version "4.4.2" + resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99" + lodash.isarguments@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a" From 0096bade70094cf6bd30e3fae5afec121e17298f Mon Sep 17 00:00:00 2001 From: Jan Christoph Bernack Date: Mon, 23 Oct 2017 16:36:31 +0200 Subject: [PATCH 2/5] Add rendering of nested properties --- src/TableBody.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/TableBody.js b/src/TableBody.js index a2a4d4b63..6e11948b3 100644 --- a/src/TableBody.js +++ b/src/TableBody.js @@ -7,6 +7,7 @@ import TableColumn from './TableColumn'; import TableEditColumn from './TableEditColumn'; import classSet from 'classnames'; import ExpandComponent from './ExpandComponent'; +import _get from 'lodash.get'; class TableBody extends Component { constructor(props) { @@ -55,7 +56,7 @@ class TableBody extends Component { let tableRows = this.props.data.map(function(data, r) { const tableColumns = this.props.columns.filter(_ => _ != null).map(function(column, i) { - const fieldValue = data[column.name]; + const fieldValue = _get(data, column.name); const isFocusCell = r === y && i === x; if (column.name !== this.props.keyField && // Key field can't be edit column.editable && // column is editable? default is true, user can set it false From fa1eac8eaed08d4e8014d0b229ce2a0d558cc03e Mon Sep 17 00:00:00 2001 From: Jan Christoph Bernack Date: Mon, 23 Oct 2017 16:37:22 +0200 Subject: [PATCH 3/5] Add sorting of columns using nested properties --- src/store/TableDataStore.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/store/TableDataStore.js b/src/store/TableDataStore.js index 4aaa94158..6b9310f41 100644 --- a/src/store/TableDataStore.js +++ b/src/store/TableDataStore.js @@ -4,6 +4,7 @@ /* eslint eqeqeq: 0 */ /* eslint one-var: 0 */ import Const from '../Const'; +import _get from 'lodash.get'; export class TableDataStore { @@ -658,8 +659,8 @@ export class TableDataStore { if (sortFunc) { result = sortFunc(a, b, sortDetails.order, sortDetails.sortField, sortFuncExtraData); } else { - const valueA = a[sortDetails.sortField] == null ? '' : a[sortDetails.sortField]; - const valueB = b[sortDetails.sortField] == null ? '' : b[sortDetails.sortField]; + const valueA = _get(a, sortDetails.sortField, ''); + const valueB = _get(b, sortDetails.sortField, ''); if (isDesc) { if (typeof valueB === 'string') { From 527f022af5117b075bec19893dce7745ba9a2d49 Mon Sep 17 00:00:00 2001 From: Jan Christoph Bernack Date: Mon, 23 Oct 2017 16:54:10 +0200 Subject: [PATCH 4/5] Add dependency on lodash.set --- package.json | 1 + yarn.lock | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/package.json b/package.json index 52d58ec4c..31dd5099b 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "dependencies": { "classnames": "^2.1.2", "lodash.get": "^4.4.2", + "lodash.set": "^4.3.2", "prop-types": "^15.5.10", "react-modal": "^3.0.3", "react-s-alert": "^1.3.0" diff --git a/yarn.lock b/yarn.lock index 6ab754832..19fc46bf9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4756,6 +4756,10 @@ lodash.restparam@^3.0.0: version "3.6.1" resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" +lodash.set@^4.3.2: + version "4.3.2" + resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23" + lodash.template@^2.4.1: version "2.4.1" resolved "https://registry.yarnpkg.com/lodash.template/-/lodash.template-2.4.1.tgz#9e611007edf629129a974ab3c48b817b3e1cf20d" From 500a09210bc74ee690f0d33d69c86d2422c0d3d5 Mon Sep 17 00:00:00 2001 From: Jan Christoph Bernack Date: Mon, 23 Oct 2017 16:54:34 +0200 Subject: [PATCH 5/5] Add filtering and editing on nested properties --- src/store/TableDataStore.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/store/TableDataStore.js b/src/store/TableDataStore.js index 6b9310f41..766f4f7d3 100644 --- a/src/store/TableDataStore.js +++ b/src/store/TableDataStore.js @@ -5,6 +5,7 @@ /* eslint one-var: 0 */ import Const from '../Const'; import _get from 'lodash.get'; +import _set from 'lodash.set'; export class TableDataStore { @@ -194,10 +195,10 @@ export class TableDataStore { const currentDisplayData = this.getCurrentDisplayData(); let rowKeyCache; if (!this.enablePagination) { - currentDisplayData[rowIndex][fieldName] = newVal; + _set(currentDisplayData[rowIndex], fieldName, newVal); rowKeyCache = currentDisplayData[rowIndex][this.keyField]; } else { - currentDisplayData[this.pageObj.start + rowIndex][fieldName] = newVal; + _set(currentDisplayData[this.pageObj.start + rowIndex], fieldName, newVal); rowKeyCache = currentDisplayData[this.pageObj.start + rowIndex][this.keyField]; } if (this.isOnFilter) { @@ -471,8 +472,8 @@ export class TableDataStore { let valid = true; let filterVal; for (const key in filterObj) { - let targetVal = row[key]; - if (targetVal === null || targetVal === undefined) { + let targetVal = _get(row, key, ''); + if (targetVal === null) { targetVal = ''; } @@ -520,9 +521,9 @@ export class TableDataStore { formatExtraData = this.colInfos[key].formatExtraData; filterValue = this.colInfos[key].filterValue; if (filterFormatted && format) { - targetVal = format(row[key], row, formatExtraData, r); + targetVal = format(targetVal, row, formatExtraData, r); } else if (filterValue) { - targetVal = filterValue(row[key], row); + targetVal = filterValue(targetVal, row); } } @@ -607,13 +608,11 @@ export class TableDataStore { filterValue, formatExtraData } = colInfo; - let targetVal; + let targetVal = _get(row, key); if (filterFormatted && format) { - targetVal = format(row[key], row, formatExtraData, r); + targetVal = format(targetVal, row, formatExtraData, r); } else if (filterValue) { - targetVal = filterValue(row[key], row); - } else { - targetVal = row[key]; + targetVal = filterValue(targetVal, row); } if (targetVal !== null && typeof targetVal !== 'undefined') { targetVal = targetVal.toString().toLowerCase();