This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,7 @@ function orderByFilter($parse){
122
122
sortPredicate = isArray ( sortPredicate ) ? sortPredicate : [ sortPredicate ] ;
123
123
if ( sortPredicate . length === 0 ) { sortPredicate = [ '+' ] ; }
124
124
sortPredicate = sortPredicate . map ( function ( predicate ) {
125
+ predicate = predicate || '' ;
125
126
var descending = false , get = predicate || identity ;
126
127
if ( isString ( predicate ) ) {
127
128
if ( ( predicate . charAt ( 0 ) == '+' || predicate . charAt ( 0 ) == '-' ) ) {
@@ -130,6 +131,12 @@ function orderByFilter($parse){
130
131
}
131
132
if ( predicate === '' ) {
132
133
// Effectively no predicate was passed so we compare identity
134
+ if ( array . some ( angular . isObject ) ) {
135
+ return function ( ) {
136
+ return descending ? 1 : 0 ;
137
+ } ;
138
+ }
139
+
133
140
return reverseComparator ( function ( a , b ) {
134
141
return compare ( a , b ) ;
135
142
} , descending ) ;
Original file line number Diff line number Diff line change @@ -91,6 +91,23 @@ describe('Filter: orderBy', function() {
91
91
. toEqualData ( [ { "원" : 31000 } , { "원" : 76000 } , { "원" : 156000 } ] ) ;
92
92
} ) ;
93
93
94
+ it ( 'should maintain order in an array of objects when no predicate is provided' , function ( ) {
95
+ var array = [ { a :1 } , { b :2 } , { c :3 } ] ;
96
+
97
+ expect ( orderBy ( array ) ) . toEqualData ( array ) ;
98
+ expect ( orderBy ( array , '' ) ) . toEqualData ( array ) ;
99
+ expect ( orderBy ( array , [ ] ) ) . toEqualData ( array ) ;
100
+ expect ( orderBy ( array , [ '' ] ) ) . toEqualData ( array ) ;
101
+ expect ( orderBy ( array , [ '+' ] ) ) . toEqualData ( array ) ;
102
+ } ) ;
103
+
104
+ it ( 'should inverse order in an array of objects when minus is provided without predicate' , function ( ) {
105
+ var array = [ { a : 1 } , { b : 2 } , { c : 3 } ] ,
106
+ inverseArray = [ { c : 3 } , { b : 2 } , { a : 1 } ] ;
107
+
108
+ expect ( orderBy ( array , [ '-' ] ) ) . toEqualData ( inverseArray ) ;
109
+ } ) ;
110
+
94
111
it ( 'should throw if quoted string predicate is quoted incorrectly' , function ( ) {
95
112
/*jshint -W008 */
96
113
expect ( function ( ) {
You can’t perform that action at this time.
0 commit comments