[Kimchi-devel] [PATCH 2/7] Update grid widget to populate fields from deeply nested objects
Adam King
rak at linux.vnet.ibm.com
Tue Mar 25 18:18:07 UTC 2014
Prior implementation of grid assumed all fields were defined as properties of
the top object with no nesting. The update facilitates use of nested objects.
Signed-off-by: Adam King <rak at linux.vnet.ibm.com>
---
ui/js/src/kimchi.grid.js | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/ui/js/src/kimchi.grid.js b/ui/js/src/kimchi.grid.js
index 540f1ba..b8346ea 100644
--- a/ui/js/src/kimchi.grid.js
+++ b/ui/js/src/kimchi.grid.js
@@ -161,6 +161,23 @@ kimchi.widget.Grid = function(params) {
var maskNode = $('.grid-mask', gridNode);
maskNode.css('top', captionHeight + 'px');
+ var getValue = function(name, obj) {
+ var result=undefined;
+ if(!Array.isArray(name)) {
+ name=kimchi.form.parseFormName(name);
+ }
+ if(name.length!=0) {
+ var tmpName=name.shift();
+ if(obj[tmpName]!=undefined) {
+ result=obj[tmpName];
+ }
+ if(name.length!=0) {
+ result=getValue(name,obj[tmpName]);
+ }
+ }
+ return(result);
+ };
+
var fillBody = function(container, fields, data) {
var tbody = ($('tbody', container).length && $('tbody', container))
|| $('<tbody></tbody>').appendTo(container);
@@ -168,13 +185,12 @@ kimchi.widget.Grid = function(params) {
$.each(data, function(i, row) {
var rowNode = $('<tr></tr>').appendTo(tbody);
$.each(fields, function(fi, field) {
- var fieldName = field['name'];
- var value = (row[fieldName]==null) ? '' : row[fieldName];
+ var value = getValue(field['name'], row);
$('<td><div class="cell-text-wrapper"' +
(field['makeTitle'] === true
? ' title="' + value + '"'
: ''
- ) + '>' + value + '</div></td>'
+ ) + '>' + value.toString() + '</div></td>'
).appendTo(rowNode);
});
});
--
1.8.1.4
More information about the Kimchi-devel
mailing list