Skip to content

Commit 839a9b6

Browse files
committed
[hotfix/6388]
- scientific notation now also gets parsed to number on sort number string, including e, Infinity and -Infinity
1 parent 4aa2cc5 commit 839a9b6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/core/src/js/services/rowSorter.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
135135
};
136136

137137

138+
function parseNumStr(numStr) {
139+
if (/^\s*-?Infinity\s*$/.test(numStr)) {//check for positive or negative Infinity and return that
140+
return parseFloat(numStr);
141+
}
142+
return parseFloat(numStr.replace(/[^0-9.eE-]/g, ''));
143+
}
144+
145+
138146
/**
139147
* @ngdoc method
140148
* @methodOf ui.grid.class:rowSorter
@@ -156,15 +164,15 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
156164
badB = false;
157165

158166
// Try to parse 'a' to a float
159-
numA = parseFloat(a.replace(/[^0-9.-]/g, ''));
167+
numA = parseNumStr(a);
160168

161169
// If 'a' couldn't be parsed to float, flag it as bad
162170
if (isNaN(numA)) {
163171
badA = true;
164172
}
165173

166174
// Try to parse 'b' to a float
167-
numB = parseFloat(b.replace(/[^0-9.-]/g, ''));
175+
numB = parseNumStr(b);
168176

169177
// If 'b' couldn't be parsed to float, flag it as bad
170178
if (isNaN(numB)) {

0 commit comments

Comments
 (0)