Skip to content

Commit

Permalink
fix(flatEntityAccess): getCellDisplayValue now returns the correct va…
Browse files Browse the repository at this point in the history
…lue.

* Fix getCellDisplayValue method when using flatEntityAccess, to now return the correct value. Before the cellDisplayGetterCache was just returning the first value cached and ignoring the row parameter

* Add unit tests around get cell value with flatEntityAccess option set
  • Loading branch information
MattOakley authored and mportuga committed Mar 24, 2017
1 parent 111afb4 commit ba77c87
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/core/factories/Grid.js
Expand Up @@ -1899,7 +1899,7 @@ angular.module('ui.grid')
if (typeof(row.entity['$$' + col.uid]) !== 'undefined') {
col.cellDisplayGetterCache = $parse(row.entity['$$' + col.uid].rendered + custom_filter);
} else if (this.options.flatEntityAccess && typeof(col.field) !== 'undefined') {
col.cellDisplayGetterCache = $parse(row.entity[col.field] + custom_filter);
col.cellDisplayGetterCache = $parse('entity.' + col.field + custom_filter);
} else {
col.cellDisplayGetterCache = $parse(row.getEntityQualifiedColField(col) + custom_filter);
}
Expand Down
47 changes: 47 additions & 0 deletions test/unit/core/factories/Grid.spec.js
Expand Up @@ -611,6 +611,36 @@ describe('Grid factory', function () {

});

it('should set cache correctly with flatEntityAccess', function() {

var colDefs = [
{name:'simpleProp'}
];
var entity2 = {
simpleProp: 'simplePropValue.2'
};

var grid = new Grid({ id: 1, columnDefs:colDefs, flatEntityAccess:true });
var rows = [
new GridRow(entity,1,grid),
new GridRow(entity2,2,grid)
];


grid.buildColumns();
grid.modifyRows([entity, entity2]);

var simpleCol = grid.getColumn('simpleProp');

var row = grid.rows[0];
expect(grid.getCellValue(row,simpleCol)).toBe('simplePropValue');
expect(grid.getCellDisplayValue(row,simpleCol)).toBe('simplePropValue');

var row2 = grid.rows[1];
expect(grid.getCellValue(row2,simpleCol)).toBe('simplePropValue.2');
expect(grid.getCellDisplayValue(row2,simpleCol)).toBe('simplePropValue.2');
});

it('should bind correctly to $$this', function() {
var colDefs = [
{name: 'thisProp', field: '$$this'}
Expand Down Expand Up @@ -652,6 +682,23 @@ describe('Grid factory', function () {
expect(grid.getCellDisplayValue(row,grid.columns[1])).toEqual("WEDNESDAY");
});

it('should apply angularjs filters with flatEntityAccess', function(){
var colDefs = [
{displayName:'date', field:'dateProp', cellFilter: 'date:"yyyy-MM-dd"'},
{displayName:'weekday', field:'dateProp', cellFilter: 'date:"EEEE" | uppercase'}
];
var grid = new Grid({ id: 1, columnDefs:colDefs, flatEntityAccess:true });
var rows = [
new GridRow(entity,1,grid)
];
grid.buildColumns();
grid.modifyRows([entity]);

var row = grid.rows[0];
expect(grid.getCellDisplayValue(row,grid.columns[0])).toEqual("2015-07-01");
expect(grid.getCellDisplayValue(row,grid.columns[1])).toEqual("WEDNESDAY");
});

it('not overwrite column types specified in options', function() {

var grid1 = new Grid({ id: 3 });
Expand Down

0 comments on commit ba77c87

Please sign in to comment.