Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 94b0f2d

Browse files
tsevanpetebacondarwin
authored andcommitted
fix(orderBy): allow arrayLike objects to be ordered
Closes #8944
1 parent c12e8d4 commit 94b0f2d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/ng/filter/orderBy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
orderByFilter.$inject = ['$parse'];
116116
function orderByFilter($parse){
117117
return function(array, sortPredicate, reverseOrder) {
118-
if (!isArray(array)) return array;
118+
if (!(isArrayLike(array))) return array;
119119
if (!sortPredicate) return array;
120120
sortPredicate = isArray(sortPredicate) ? sortPredicate: [sortPredicate];
121121
sortPredicate = map(sortPredicate, function(predicate){

test/ng/filter/orderBySpec.js

+13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ describe('Filter: orderBy', function() {
1717
expect(orderBy([{a:15}, {a:2}], 'a', "reverse")).toEqualData([{a:15}, {a:2}]);
1818
});
1919

20+
it('should sort inherited from array', function(){
21+
function BaseCollection(){}
22+
BaseCollection.prototype = Array.prototype;
23+
var child = new BaseCollection();
24+
child.push({a:2});
25+
child.push({a:15});
26+
27+
expect(Array.isArray(child)).toBe(false);
28+
expect(child instanceof Array).toBe(true);
29+
30+
expect(orderBy(child, 'a', true)).toEqualData([{a:15}, {a:2}]);
31+
});
32+
2033
it('should sort array by predicate', function() {
2134
expect(orderBy([{a:15, b:1}, {a:2, b:1}], ['a', 'b'])).toEqualData([{a:2, b:1}, {a:15, b:1}]);
2235
expect(orderBy([{a:15, b:1}, {a:2, b:1}], ['b', 'a'])).toEqualData([{a:2, b:1}, {a:15, b:1}]);

0 commit comments

Comments
 (0)