From 5b580fe826cf642f6133ae90957b591d73d9a928 Mon Sep 17 00:00:00 2001 From: Ben Rexin Date: Mon, 25 Nov 2013 17:26:48 +0100 Subject: [PATCH] feat(orderBy): support sorting of umlauts Compare Strings using the localeCompare method if available. --- src/ng/filter/orderBy.js | 7 +++++-- test/ng/filter/orderBySpec.js | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ng/filter/orderBy.js b/src/ng/filter/orderBy.js index 961faa368642..b8d3e302d342 100644 --- a/src/ng/filter/orderBy.js +++ b/src/ng/filter/orderBy.js @@ -123,8 +123,11 @@ function orderByFilter($parse){ var t2 = typeof v2; if (t1 == t2) { if (t1 == "string") { - v1 = v1.toLowerCase(); - v2 = v2.toLowerCase(); + v1 = v1.toLowerCase(); + v2 = v2.toLowerCase(); + if (typeof v1.localeCompare == 'function') { + return v1.localeCompare(v2); + } } if (v1 === v2) return 0; return v1 < v2 ? -1 : 1; diff --git a/test/ng/filter/orderBySpec.js b/test/ng/filter/orderBySpec.js index 5c1178910255..15a41a0f220e 100644 --- a/test/ng/filter/orderBySpec.js +++ b/test/ng/filter/orderBySpec.js @@ -23,6 +23,10 @@ describe('Filter: orderBy', function() { expect(orderBy([{a:15, b:1}, {a:2, b:1}], ['+b', '-a'])).toEqualData([{a:15, b:1}, {a:2, b:1}]); }); + it('should sort strings via localeCompare', function() { + expect(orderBy([{a:'ö'},{a:'a'},{a:'z'}], 'a')).toEqualData([{a:'a'},{a:'ö'},{a:'z'}]); + }); + it('should use function', function() { expect( orderBy(