Skip to content

Commit be80ceb

Browse files
rloisel-forcitymportuga
authored andcommitted
fix(#6270): Update getCellDisplayValue to manage special case with flatEntityAccess (#6271)
* fix #6270: Update getCellDisplayValue to manage special case with flatEntityAccess * add unit test and fix issues with quote and backslash
1 parent 43ffebb commit be80ceb

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

src/js/core/factories/Grid.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,8 @@ 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('entity.' + col.field + custom_filter);
1902+
var colField = col.field.replace(/(')|(\\)/g, "\\$&");
1903+
col.cellDisplayGetterCache = $parse('entity[\'' + colField + '\']' + custom_filter);
19031904
} else {
19041905
col.cellDisplayGetterCache = $parse(row.getEntityQualifiedColField(col) + custom_filter);
19051906
}

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ describe('Grid factory', function () {
699699
var row = grid.rows[0];
700700
expect(grid.getCellValue(row,simpleCol)).toBe('simplePropValue');
701701
expect(grid.getCellDisplayValue(row,simpleCol)).toBe('simplePropValue');
702-
702+
703703
var row2 = grid.rows[1];
704704
expect(grid.getCellValue(row2,simpleCol)).toBe('simplePropValue.2');
705705
expect(grid.getCellDisplayValue(row2,simpleCol)).toBe('simplePropValue.2');
@@ -763,6 +763,49 @@ describe('Grid factory', function () {
763763
expect(grid.getCellDisplayValue(row,grid.columns[1])).toEqual("WEDNESDAY");
764764
});
765765

766+
it('should get cell display value with special chars column name and flatEntityAccess', function() {
767+
var colDefs = [
768+
{name: 'Column 1', field: 'column.1'},
769+
{name: 'Column 2', field: 'column \'2\'', cellFilter: 'number:2'},
770+
{name: 'Column 3', field: 'column 3'},
771+
{name: 'Column 4', field: '\\\\////&é"(-è_çà)=+{}:/\\_!<>*|\',?;.§$ꣵ%'}
772+
];
773+
var grid = new Grid({ id: 1, columnDefs:colDefs, flatEntityAccess:true });
774+
var data = [
775+
{
776+
'column.1': 'test',
777+
'column \'2\'': 2,
778+
'column 3': '3',
779+
'\\\\////&é"(-è_çà)=+{}:/\\_!<>*|\',?;.§$ꣵ%': '&é"(-è_çà)=+{}'
780+
},
781+
{
782+
'column.1': 'test1',
783+
'column \'2\'': 3,
784+
'column 3': '4',
785+
'\\\\////&é"(-è_çà)=+{}:/\\_!<>*|\',?;.§$ꣵ%': ''
786+
}
787+
];
788+
var rows = [
789+
new GridRow(data[0], 1, grid),
790+
new GridRow(data[1], 2, grid)
791+
];
792+
793+
grid.buildColumns();
794+
grid.modifyRows(data);
795+
796+
expect(grid.getCellDisplayValue(rows[0], grid.getColumn('Column 1'))).toBe('test');
797+
expect(grid.getCellDisplayValue(rows[1], grid.getColumn('Column 1'))).toBe('test1');
798+
799+
expect(grid.getCellDisplayValue(rows[0], grid.getColumn('Column 2'))).toBe('2.00');
800+
expect(grid.getCellDisplayValue(rows[1], grid.getColumn('Column 2'))).toBe('3.00');
801+
802+
expect(grid.getCellDisplayValue(rows[0], grid.getColumn('Column 3'))).toBe('3');
803+
expect(grid.getCellDisplayValue(rows[1], grid.getColumn('Column 3'))).toBe('4');
804+
805+
expect(grid.getCellDisplayValue(rows[0], grid.getColumn('Column 4'))).toBe('&é"(-è_çà)=+{}');
806+
expect(grid.getCellDisplayValue(rows[1], grid.getColumn('Column 4'))).toBe('');
807+
});
808+
766809
it('not overwrite column types specified in options', function() {
767810

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

0 commit comments

Comments
 (0)