Skip to content

Commit

Permalink
fix(#6270): Update getCellDisplayValue to manage special case with fl…
Browse files Browse the repository at this point in the history
…atEntityAccess (#6271)

* fix #6270: Update getCellDisplayValue to manage special case with flatEntityAccess

* add unit test and fix issues with quote and backslash
  • Loading branch information
rloisel-forcity authored and mportuga committed Jun 19, 2017
1 parent 43ffebb commit be80ceb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/js/core/factories/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -1899,7 +1899,8 @@ 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('entity.' + col.field + custom_filter);
var colField = col.field.replace(/(')|(\\)/g, "\\$&");
col.cellDisplayGetterCache = $parse('entity[\'' + colField + '\']' + custom_filter);
} else {
col.cellDisplayGetterCache = $parse(row.getEntityQualifiedColField(col) + custom_filter);
}
Expand Down
45 changes: 44 additions & 1 deletion test/unit/core/factories/Grid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ describe('Grid factory', function () {
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');
Expand Down Expand Up @@ -763,6 +763,49 @@ describe('Grid factory', function () {
expect(grid.getCellDisplayValue(row,grid.columns[1])).toEqual("WEDNESDAY");
});

it('should get cell display value with special chars column name and flatEntityAccess', function() {
var colDefs = [
{name: 'Column 1', field: 'column.1'},
{name: 'Column 2', field: 'column \'2\'', cellFilter: 'number:2'},
{name: 'Column 3', field: 'column 3'},
{name: 'Column 4', field: '\\\\////&é"(-è_çà)=+{}:/\\_!<>*|\',?;.§$ꣵ%'}
];
var grid = new Grid({ id: 1, columnDefs:colDefs, flatEntityAccess:true });
var data = [
{
'column.1': 'test',
'column \'2\'': 2,
'column 3': '3',
'\\\\////&é"(-è_çà)=+{}:/\\_!<>*|\',?;.§$ꣵ%': '&é"(-è_çà)=+{}'
},
{
'column.1': 'test1',
'column \'2\'': 3,
'column 3': '4',
'\\\\////&é"(-è_çà)=+{}:/\\_!<>*|\',?;.§$ꣵ%': ''
}
];
var rows = [
new GridRow(data[0], 1, grid),
new GridRow(data[1], 2, grid)
];

grid.buildColumns();
grid.modifyRows(data);

expect(grid.getCellDisplayValue(rows[0], grid.getColumn('Column 1'))).toBe('test');
expect(grid.getCellDisplayValue(rows[1], grid.getColumn('Column 1'))).toBe('test1');

expect(grid.getCellDisplayValue(rows[0], grid.getColumn('Column 2'))).toBe('2.00');
expect(grid.getCellDisplayValue(rows[1], grid.getColumn('Column 2'))).toBe('3.00');

expect(grid.getCellDisplayValue(rows[0], grid.getColumn('Column 3'))).toBe('3');
expect(grid.getCellDisplayValue(rows[1], grid.getColumn('Column 3'))).toBe('4');

expect(grid.getCellDisplayValue(rows[0], grid.getColumn('Column 4'))).toBe('&é"(-è_çà)=+{}');
expect(grid.getCellDisplayValue(rows[1], grid.getColumn('Column 4'))).toBe('');
});

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

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

0 comments on commit be80ceb

Please sign in to comment.