The solution is to define a cellTemplate for this column using row.entity[col.field] instead of default row.getProperty(col.field) method.
var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
$scope.myData = [{
"xyz.name": "Moroni",
age: 50
}, {
"xyz.name": "Enos",
age: 34
}];
var colDefs = [{
field: 'xyz.name',
cellTemplate: '<div>{{row.entity[col.field]}}</div>'
}, {
field: 'age'
}
];
$scope.gridOptions = {
data: 'myData',
columnDefs: colDefs
};
});
- The plunkr is working perfectly now. http://plnkr.co/edit/xeLCGuSjrbGyiPgw7q75?p=preview
so, what's wrong with default cellTemplate?
the default cellTemplate used in ng-grid is like this:
<div class="ngCellText" ng-class="col.colIndex()"><span ng-cell-text>{{row.getProperty(col.field)}}</span></div>
it uses row.getProperty()
method which eventually calls angular $parse service. it will evaluate the argument which treats the .
as child operator.
so in this case 'xyz.name' actually maps to json data structure like this:
xyz:{name: "moroni"}
row.entity[col.field]
just maps the data like a hashmap, so it will serve the purpose here.