Reputation: 5503
In ng-grid I need one of my columns to show a value that is dependent on multiple properties of my object. So I need to pass the whole object and not just one of its properties.
In another location of the project, I solved this by wrapping my objects in another object's say, value
property, so for example one column was bound to value.FirstName
and another one just to value
.
Is there a way to avoid this warping, for example to just pass an empty field
property, or just dropping the field
property? Non of these methods seem to work.
Thanks
Upvotes: 1
Views: 1336
Reputation: 3870
Do not set a field
and then use row.entity
in the cellTemplate
. Here is an example:
$scope.myData = [
{
firstName: 'Bob',
lastName: 'Smith',
age: 43
},
{
firstName: 'Joe',
lastName: 'Williams',
age: 39
}
];
$scope.gridOptions = {
data: myData,
colDefs: [
{
displayName: 'Name',
cellTemplate: '<div>{{row.entity.firstName}} {{row.entity.lastName}}</div>'
},
{
displayName: 'Age',
field: age
}
]
};
This will result in a table like this:
+--------------+-----+
| Name | Age |
+--------------+-----+
| Bob Smith | 43 |
+--------------+-----+
| Joe Williams | 39 |
+--------------+-----+
Upvotes: 4
Reputation: 1409
You can use row.entity object which can be referenced from any place of the cell template. It is linked to the whole object for the current row when building the grid.
Upvotes: 1