trNgGrid icon indicating copy to clipboard operation
trNgGrid copied to clipboard

Nested objects and arrays not working - Beta 3.0

Open rphilp opened this issue 12 years ago • 3 comments

This is another issue that arose while I was playing with a data set. I can access the entire subarray, but not individual elements. Example: {{owner.login}} works in html, however owner.login does not work as a field name. Using owner will pull the entire owner array and display it in the table.

Sample Dataset: https://api.github.com/users/mralexgray/repos

I was using ngGrid before and it worked there, so I dug around and ripped a small section of code from them and it worked well.

Present Code:

if (fieldName) {
     var displayFormat = gridColumnDef.displayFormat;
     if (displayFormat) {
          // apply the format
          if (displayFormat[0] == ".") {
               outputItem[fieldName] = eval("inputItem[fieldName]" + displayFormat);
          } else {
               // angular filter
               outputItem[fieldName] = scope.$eval("gridOptions.items[" + inputIndex + "]['" + fieldName + "'] | " + displayFormat);
          }
     } else {
          outputItem[fieldName] = inputItem[fieldName];
     }

Updated Code:

if (fieldName) {
     var displayFormat = gridColumnDef.displayFormat;
     if (displayFormat) {
          // apply the format
          if (displayFormat[0] == ".") {
               outputItem[fieldName] = eval("inputItem[fieldName]" + displayFormat);
          } else {
               // angular filter
               outputItem[fieldName] = scope.$eval("gridOptions.items[" + inputIndex + "]['" + fieldName + "'] | " + displayFormat);
          }
     } else {
          if (fieldName.match(/\./g)) {
               var properties = fieldName.split('.');
               var currentProperty = inputItem;
               for (var j = 0; j < properties.length - 1; j++) {
                    currentProperty[properties[j]] = currentProperty[properties[j]] || {};
                    currentProperty = currentProperty[properties[j]];
               }
               outputItem[fieldName] = currentProperty[properties[properties.length - 1]];
          } else {
               outputItem[fieldName] = inputItem[fieldName];
          }
     }

rphilp avatar Jul 16 '14 02:07 rphilp

Thanks for reporting this issue. The so called field could actually be much more complex than that. Let me quickly create a test for this one and will come back to you asap.

MoonStorm avatar Jul 17 '14 10:07 MoonStorm

Column filters were also not working with nested objects or arrays. The changes were not trivial. I've updated the Column Definition section on the demo site with some relevant samples.

MoonStorm avatar Jul 17 '14 15:07 MoonStorm

Well done. I've tested it on one data source and it works great. I'll test it on another tomorrow and let you know how that goes.

The updated documentation looks good as well.

Thanks for showing me I have a LONG way to go to a good understanding of this stuff.

rphilp avatar Jul 17 '14 23:07 rphilp