Skip to content

Commit

Permalink
Fixed #555 - DataTable crashes with a "Cannot read property 'xxx' of …
Browse files Browse the repository at this point in the history
…null" for nested objects
  • Loading branch information
cagataycivici committed Oct 22, 2020
1 parent 074538a commit 30daa63
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/components/utils/ObjectUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,32 @@ export default class ObjectUtils {
}

static resolveFieldData(data, field) {
if (typeof field === 'function') {
return field(data);
}
else {
if (data && field) {
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) {
value = value[fields[i]];
}
return value;
}
if (data && field) {
if (this.isFunction(field)) {
return field(data);
}
else if(field.indexOf('.') === -1) {
return data[field];
}
else {
return null;
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;
}
}
else {
return null;
}
}

static isFunction(obj) {
return !!(obj && obj.constructor && obj.call && obj.apply);
}

static filter(value, fields, filterValue) {
Expand Down

0 comments on commit 30daa63

Please sign in to comment.