From 56fda75e22abc50b086c315d706ec396281a5edb Mon Sep 17 00:00:00 2001 From: Ventsislav Mladenov Date: Mon, 27 Jan 2014 12:20:49 +0200 Subject: [PATCH] Ability to reference nested properties in fieldName --- dev/jquery.jtable.core.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dev/jquery.jtable.core.js b/dev/jquery.jtable.core.js index 62a3d95c..2431f27e 100644 --- a/dev/jquery.jtable.core.js +++ b/dev/jquery.jtable.core.js @@ -664,11 +664,21 @@ /* RENDERING FIELD VALUES ***********************************************/ + /* Gets value by fieldname including nested properties. + *************************************************************************/ + _getFieldValue: function (obj, fieldName) { + if (fieldName.indexOf(".") == -1) + return obj[fieldName]; + var arr = fieldName.split("."); + while(arr.length && (obj = obj[arr.shift()])); + return obj; + }, + /* Gets text for a field of a record according to it's type. *************************************************************************/ _getDisplayTextForRecordField: function (record, fieldName) { var field = this.options.fields[fieldName]; - var fieldValue = record[fieldName]; + var fieldValue = this._getFieldValue(record, fieldName); //if this is a custom field, call display function if (field.display) {