@@ -5,14 +5,14 @@ var module = angular.module('ui.grid');
5
5
/**
6
6
* @ngdoc object
7
7
* @name ui.grid.class:RowSorter
8
- * @description RowSorter provides the default sorting mechanisms,
9
- * including guessing column types and applying appropriate sort
8
+ * @description RowSorter provides the default sorting mechanisms,
9
+ * including guessing column types and applying appropriate sort
10
10
* algorithms
11
- *
12
- */
11
+ *
12
+ */
13
13
14
14
module . service ( 'rowSorter' , [ '$parse' , 'uiGridConstants' , function ( $parse , uiGridConstants ) {
15
- var currencyRegexStr =
15
+ var currencyRegexStr =
16
16
'(' +
17
17
uiGridConstants . CURRENCY_SYMBOLS
18
18
. map ( function ( a ) { return '\\' + a ; } ) // Escape all the currency symbols ($ at least will jack up this regex)
@@ -95,7 +95,7 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
95
95
* @methodOf ui.grid.class:RowSorter
96
96
* @name basicSort
97
97
* @description Sorts any values that provide the < method, including strings
98
- * or numbers. Handles nulls and undefined through calling handleNulls
98
+ * or numbers. Handles nulls and undefined through calling handleNulls
99
99
* @param {object } a sort value a
100
100
* @param {object } b sort value b
101
101
* @returns {number } normal sort function, returns -ve, 0, +ve
@@ -120,7 +120,7 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
120
120
* @ngdoc method
121
121
* @methodOf ui.grid.class:RowSorter
122
122
* @name sortNumber
123
- * @description Sorts numerical values. Handles nulls and undefined through calling handleNulls
123
+ * @description Sorts numerical values. Handles nulls and undefined through calling handleNulls
124
124
* @param {object } a sort value a
125
125
* @param {object } b sort value b
126
126
* @returns {number } normal sort function, returns -ve, 0, +ve
@@ -139,8 +139,8 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
139
139
* @ngdoc method
140
140
* @methodOf ui.grid.class:RowSorter
141
141
* @name sortNumberStr
142
- * @description Sorts numerical values that are stored in a string (i.e. parses them to numbers first).
143
- * Handles nulls and undefined through calling handleNulls
142
+ * @description Sorts numerical values that are stored in a string (i.e. parses them to numbers first).
143
+ * Handles nulls and undefined through calling handleNulls
144
144
* @param {object } a sort value a
145
145
* @param {object } b sort value b
146
146
* @returns {number } normal sort function, returns -ve, 0, +ve
@@ -154,36 +154,36 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
154
154
numB , // The parsed number form of 'b'
155
155
badA = false ,
156
156
badB = false ;
157
-
157
+
158
158
// Try to parse 'a' to a float
159
159
numA = parseFloat ( a . replace ( / [ ^ 0 - 9 . - ] / g, '' ) ) ;
160
-
160
+
161
161
// If 'a' couldn't be parsed to float, flag it as bad
162
162
if ( isNaN ( numA ) ) {
163
163
badA = true ;
164
164
}
165
-
165
+
166
166
// Try to parse 'b' to a float
167
167
numB = parseFloat ( b . replace ( / [ ^ 0 - 9 . - ] / g, '' ) ) ;
168
-
168
+
169
169
// If 'b' couldn't be parsed to float, flag it as bad
170
170
if ( isNaN ( numB ) ) {
171
171
badB = true ;
172
172
}
173
-
173
+
174
174
// We want bad ones to get pushed to the bottom... which effectively is "greater than"
175
175
if ( badA && badB ) {
176
176
return 0 ;
177
177
}
178
-
178
+
179
179
if ( badA ) {
180
180
return 1 ;
181
181
}
182
-
182
+
183
183
if ( badB ) {
184
184
return - 1 ;
185
185
}
186
-
186
+
187
187
return numA - numB ;
188
188
}
189
189
} ;
@@ -193,7 +193,7 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
193
193
* @ngdoc method
194
194
* @methodOf ui.grid.class:RowSorter
195
195
* @name sortAlpha
196
- * @description Sorts string values. Handles nulls and undefined through calling handleNulls
196
+ * @description Sorts string values. Handles nulls and undefined through calling handleNulls
197
197
* @param {object } a sort value a
198
198
* @param {object } b sort value b
199
199
* @returns {number } normal sort function, returns -ve, 0, +ve
@@ -205,7 +205,7 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
205
205
} else {
206
206
var strA = a . toString ( ) . toLowerCase ( ) ,
207
207
strB = b . toString ( ) . toLowerCase ( ) ;
208
-
208
+
209
209
return strA === strB ? 0 : strA . localeCompare ( strB ) ;
210
210
}
211
211
} ;
@@ -234,7 +234,7 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
234
234
}
235
235
var timeA = a . getTime ( ) ,
236
236
timeB = b . getTime ( ) ;
237
-
237
+
238
238
return timeA === timeB ? 0 : ( timeA < timeB ? - 1 : 1 ) ;
239
239
}
240
240
} ;
@@ -244,8 +244,8 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
244
244
* @ngdoc method
245
245
* @methodOf ui.grid.class:RowSorter
246
246
* @name sortBool
247
- * @description Sorts boolean values, true is considered larger than false.
248
- * Handles nulls and undefined through calling handleNulls
247
+ * @description Sorts boolean values, true is considered larger than false.
248
+ * Handles nulls and undefined through calling handleNulls
249
249
* @param {object } a sort value a
250
250
* @param {object } b sort value b
251
251
* @returns {number } normal sort function, returns -ve, 0, +ve
@@ -258,7 +258,7 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
258
258
if ( a && b ) {
259
259
return 0 ;
260
260
}
261
-
261
+
262
262
if ( ! a && ! b ) {
263
263
return 0 ;
264
264
}
@@ -273,17 +273,17 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
273
273
* @ngdoc method
274
274
* @methodOf ui.grid.class:RowSorter
275
275
* @name getSortFn
276
- * @description Get the sort function for the column. Looks first in
276
+ * @description Get the sort function for the column. Looks first in
277
277
* rowSorter.colSortFnCache using the column name, failing that it
278
278
* looks at col.sortingAlgorithm (and puts it in the cache), failing that
279
279
* it guesses the sort algorithm based on the data type.
280
- *
280
+ *
281
281
* The cache currently seems a bit pointless, as none of the work we do is
282
282
* processor intensive enough to need caching. Presumably in future we might
283
283
* inspect the row data itself to guess the sort function, and in that case
284
284
* it would make sense to have a cache, the infrastructure is in place to allow
285
285
* that.
286
- *
286
+ *
287
287
* @param {Grid } grid the grid to consider
288
288
* @param {GridCol } col the column to find a function for
289
289
* @param {array } rows an array of grid rows. Currently unused, but presumably in future
@@ -336,7 +336,7 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
336
336
* @description Used where multiple columns are present in the sort criteria,
337
337
* we determine which column should take precedence in the sort by sorting
338
338
* the columns based on their sort.priority
339
- *
339
+ *
340
340
* @param {gridColumn } a column a
341
341
* @param {gridColumn } b column b
342
342
* @returns {number } normal sort function, returns -ve, 0, +ve
@@ -358,11 +358,11 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
358
358
}
359
359
}
360
360
// Only A has a priority
361
- else if ( a . sort . priority || a . sort . priority === 0 ) {
361
+ else if ( a . sort . priority || a . sort . priority === undefined ) {
362
362
return - 1 ;
363
363
}
364
364
// Only B has a priority
365
- else if ( b . sort . priority || b . sort . priority === 0 ) {
365
+ else if ( b . sort . priority || b . sort . priority === undefined ) {
366
366
return 1 ;
367
367
}
368
368
// Neither has a priority
@@ -379,14 +379,14 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
379
379
* @description Prevents the internal sorting from executing. Events will
380
380
* still be fired when the sort changes, and the sort information on
381
381
* the columns will be updated, allowing an external sorter (for example,
382
- * server sorting) to be implemented. Defaults to false.
383
- *
382
+ * server sorting) to be implemented. Defaults to false.
383
+ *
384
384
*/
385
385
/**
386
386
* @ngdoc method
387
387
* @methodOf ui.grid.class:RowSorter
388
388
* @name sort
389
- * @description sorts the grid
389
+ * @description sorts the grid
390
390
* @param {Object } grid the grid itself
391
391
* @param {array } rows the rows to be sorted
392
392
* @param {array } columns the columns in which to look
@@ -398,7 +398,7 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
398
398
if ( ! rows ) {
399
399
return ;
400
400
}
401
-
401
+
402
402
if ( grid . options . useExternalSorting ) {
403
403
return rows ;
404
404
}
@@ -460,7 +460,7 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
460
460
idx ++ ;
461
461
}
462
462
463
- // Chrome doesn't implement a stable sort function. If our sort returns 0
463
+ // Chrome doesn't implement a stable sort function. If our sort returns 0
464
464
// (i.e. the items are equal), and we're at the last sort column in the list,
465
465
// then return the previous order using our custom
466
466
// index variable
@@ -477,13 +477,13 @@ module.service('rowSorter', ['$parse', 'uiGridConstants', function ($parse, uiGr
477
477
} ;
478
478
479
479
var newRows = rows . sort ( rowSortFn ) ;
480
-
480
+
481
481
// remove the custom index field on each row, used to make a stable sort out of unstable sorts (e.g. Chrome)
482
482
var clearIndex = function ( row , idx ) {
483
483
delete row . entity . $$uiGridIndex ;
484
484
} ;
485
485
rows . forEach ( clearIndex ) ;
486
-
486
+
487
487
return newRows ;
488
488
} ;
489
489
0 commit comments