Skip to content

Commit

Permalink
fix(cellNav): notifyText incorrect if cellFilter had string literal p…
Browse files Browse the repository at this point in the history
…arameter (#5404)

* Fixing notify text if cellFilter takes string literal

Calling getCellDisplayValue to get the correct filtered value, instead of getIntersectionValueFiltered, which did not return the correct value if the cellFIlter contained a string literal as an argument.  This was the only place that function was being used, so it can be removed.  It was probably carried forward from the ng-grid source, which had the same issue.

* Remove getIntersectionValueFiltered

This function was probably carried forward from ng-grid, and does not properly handle cellFilters with string literal arguments.  It was only being used in one place, and was easily replaced with getCellDisplayValue, which does return the proper value.
  • Loading branch information
MikeMatusz authored and JLLeitschuh committed May 27, 2016
1 parent 8dd5204 commit 08a9b68
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 36 deletions.
2 changes: 1 addition & 1 deletion src/features/cellnav/js/cellnav.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@
var values = [];
var currentSelection = grid.api.cellNav.getCurrentSelection();
for (var i = 0; i < currentSelection.length; i++) {
values.push(currentSelection[i].getIntersectionValueFiltered());
values.push(grid.getCellDisplayValue(currentSelection[i].row, currentSelection[i].col));
}
var cellText = values.toString();
setNotifyText(cellText);
Expand Down
35 changes: 0 additions & 35 deletions src/js/core/factories/GridRowColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,6 @@
var context = this.row;
return getter(context);
};
/**
* @ngdoc function
* @name getIntersectionValueFiltered
* @methodOf ui.grid.class:GridRowColumn
* @description Gets the intersection of where the row and column meet.
* @returns {String|Number|Object} The value from the grid data that this GridRowColumn points too.
* If the column has a cellFilter this will also apply the filter to it and return the value that the filter displays.
*/
GridRowColumn.prototype.getIntersectionValueFiltered = function(){
var value = this.getIntersectionValueRaw();
if (this.col.cellFilter && this.col.cellFilter !== ''){
var getFilterIfExists = function(filterName){
try {
return $filter(filterName);
} catch (e){
return null;
}
};
var filter = getFilterIfExists(this.col.cellFilter);
if (filter) { // Check if this is filter name or a filter string
value = filter(value);
} else { // We have the template version of a filter so we need to parse it apart
// Get the filter params out using a regex
// Test out this regex here https://regex101.com/r/rC5eR5/2
var re = /([^:]*):([^:]*):?([\s\S]+)?/;
var matches;
if ((matches = re.exec(this.col.cellFilter)) !== null) {
// View your result using the matches-variable.
// eg matches[0] etc.
value = $filter(matches[1])(value, matches[2], matches[3]);
}
}
}
return value;
};
return GridRowColumn;
}
]);
Expand Down

1 comment on commit 08a9b68

@chirpi
Copy link

@chirpi chirpi commented on 08a9b68 Jul 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have encountered an issue after this fix in my application. $parse() function is throwing error when cellNav is enabled.

Sample cell content: Testing - updated from command line. 1.5.7

Error Message:
Syntax Error: Token 'from' is an unexpected token at column 20 of the expression [Testing - updated from command line. 1.5.7] starting at [from command line. 1.5.7].
http://errors.angularjs.org/1.5.7/$parse/syntax?p0=from&p1=is%20an%20unexpected%20token&p2=20&p3=Testing%20%20-%20updatedNaNrom"

Please sign in to comment.