Skip to content

Commit ba77c87

Browse files
MattOakleymportuga
authored andcommitted
fix(flatEntityAccess): getCellDisplayValue now returns the correct value.
* 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
1 parent 111afb4 commit ba77c87

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/js/core/factories/Grid.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,7 @@ angular.module('ui.grid')
18991899
if (typeof(row.entity['$$' + col.uid]) !== 'undefined') {
19001900
col.cellDisplayGetterCache = $parse(row.entity['$$' + col.uid].rendered + custom_filter);
19011901
} else if (this.options.flatEntityAccess && typeof(col.field) !== 'undefined') {
1902-
col.cellDisplayGetterCache = $parse(row.entity[col.field] + custom_filter);
1902+
col.cellDisplayGetterCache = $parse('entity.' + col.field + custom_filter);
19031903
} else {
19041904
col.cellDisplayGetterCache = $parse(row.getEntityQualifiedColField(col) + custom_filter);
19051905
}

test/unit/core/factories/Grid.spec.js

+47
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,36 @@ describe('Grid factory', function () {
611611

612612
});
613613

614+
it('should set cache correctly with flatEntityAccess', function() {
615+
616+
var colDefs = [
617+
{name:'simpleProp'}
618+
];
619+
var entity2 = {
620+
simpleProp: 'simplePropValue.2'
621+
};
622+
623+
var grid = new Grid({ id: 1, columnDefs:colDefs, flatEntityAccess:true });
624+
var rows = [
625+
new GridRow(entity,1,grid),
626+
new GridRow(entity2,2,grid)
627+
];
628+
629+
630+
grid.buildColumns();
631+
grid.modifyRows([entity, entity2]);
632+
633+
var simpleCol = grid.getColumn('simpleProp');
634+
635+
var row = grid.rows[0];
636+
expect(grid.getCellValue(row,simpleCol)).toBe('simplePropValue');
637+
expect(grid.getCellDisplayValue(row,simpleCol)).toBe('simplePropValue');
638+
639+
var row2 = grid.rows[1];
640+
expect(grid.getCellValue(row2,simpleCol)).toBe('simplePropValue.2');
641+
expect(grid.getCellDisplayValue(row2,simpleCol)).toBe('simplePropValue.2');
642+
});
643+
614644
it('should bind correctly to $$this', function() {
615645
var colDefs = [
616646
{name: 'thisProp', field: '$$this'}
@@ -652,6 +682,23 @@ describe('Grid factory', function () {
652682
expect(grid.getCellDisplayValue(row,grid.columns[1])).toEqual("WEDNESDAY");
653683
});
654684

685+
it('should apply angularjs filters with flatEntityAccess', function(){
686+
var colDefs = [
687+
{displayName:'date', field:'dateProp', cellFilter: 'date:"yyyy-MM-dd"'},
688+
{displayName:'weekday', field:'dateProp', cellFilter: 'date:"EEEE" | uppercase'}
689+
];
690+
var grid = new Grid({ id: 1, columnDefs:colDefs, flatEntityAccess:true });
691+
var rows = [
692+
new GridRow(entity,1,grid)
693+
];
694+
grid.buildColumns();
695+
grid.modifyRows([entity]);
696+
697+
var row = grid.rows[0];
698+
expect(grid.getCellDisplayValue(row,grid.columns[0])).toEqual("2015-07-01");
699+
expect(grid.getCellDisplayValue(row,grid.columns[1])).toEqual("WEDNESDAY");
700+
});
701+
655702
it('not overwrite column types specified in options', function() {
656703

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

0 commit comments

Comments
 (0)