From 731da1f42d1d6ed9c0a212d672aed8479cd580b3 Mon Sep 17 00:00:00 2001 From: mertsincan Date: Thu, 28 Feb 2019 15:55:06 +0300 Subject: [PATCH] Fixed #791 - DataTable crashes with a "Cannot read property 'xxx' of undefined" for nested objects --- src/components/utils/ObjectUtils.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/utils/ObjectUtils.js b/src/components/utils/ObjectUtils.js index f306637ab1..64217b86f0 100644 --- a/src/components/utils/ObjectUtils.js +++ b/src/components/utils/ObjectUtils.js @@ -56,13 +56,19 @@ export default class ObjectUtils { static resolveFieldData(data, field) { if(data && field) { - if(field.indexOf('.') === -1) { + if (this.isFunction(field)) { + return field(data); + } + else if(field.indexOf('.') === -1) { return data[field]; } else { let fields = field.split('.'); let value = data; for(var i = 0, len = fields.length; i < len; ++i) { + if (value == null) { + return null; + } value = value[fields[i]]; } return value; @@ -72,6 +78,11 @@ export default class ObjectUtils { return null; } } + + static isFunction(obj) { + return !!(obj && obj.constructor && obj.call && obj.apply); + } + static filter(value, fields, filterValue) { var filteredItems=[];