From 438fbb26ce8a7738372d8be5edf7cf001fbf3039 Mon Sep 17 00:00:00 2001 From: Allan Watson Date: Thu, 20 Oct 2016 13:49:18 -0400 Subject: [PATCH 1/3] docs(orderBy): Clarify behavior of default comparator Documentation updates to clarify default sort behavior. See https://github.com/angular/angular.js/issues/15293 for more information --- docs/content/guide/migration.ngdoc | 10 ++++++++++ src/ng/filter/orderBy.js | 3 +++ 2 files changed, 13 insertions(+) diff --git a/docs/content/guide/migration.ngdoc b/docs/content/guide/migration.ngdoc index 6ddb29cb5a25..003315e46a4b 100644 --- a/docs/content/guide/migration.ngdoc +++ b/docs/content/guide/migration.ngdoc @@ -1226,6 +1226,16 @@ or simply use: As communicated before, IE8 is no longer supported. +### Filters (`orderBy`) + +- due to [a097aa95](https://github.com/angular/angular.js/commit/a097aa95b7c78beab6d1b7d521c25f7d9d7843d9), + the default orderBy comparator sorts null values (strings, objects, etc.) as if they were the string `'null'`: + a null string will be sorted as if it started with the letter N. To sort nonexistent items to the last (or first, + if sort order is reversed) positions in the sort results, the sort predicate should use the empty string instead + of null. Similarly, predicate values that are `undefined` will be sorted as if they were strings starting with + the letter U. + + diff --git a/src/ng/filter/orderBy.js b/src/ng/filter/orderBy.js index a86f3a82ab90..cf32e2dbcf7a 100644 --- a/src/ng/filter/orderBy.js +++ b/src/ng/filter/orderBy.js @@ -86,6 +86,9 @@ * * **Note:** If you notice numbers not being sorted as expected, make sure they are actually being * saved as numbers and not strings. + * **Note:** If null or undefined values are not being sorted as expected, convert them to the empty + * string before sorting. This is because of rule number 1 above which sorts `null` as `'null'` + * and `undefined` as `'undefined'`. * * @param {Array|ArrayLike} collection - The collection (array or array-like object) to sort. * @param {(Function|string|Array.)=} expression - A predicate (or list of From 1541f71782e18a274eabc266a6ffe652e7036d05 Mon Sep 17 00:00:00 2001 From: Allan Watson Date: Thu, 20 Oct 2016 14:49:16 -0400 Subject: [PATCH 2/3] Re-wording as suggested in review. --- docs/content/guide/migration.ngdoc | 5 +---- src/ng/filter/orderBy.js | 5 ++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/docs/content/guide/migration.ngdoc b/docs/content/guide/migration.ngdoc index 003315e46a4b..c2494d1c1970 100644 --- a/docs/content/guide/migration.ngdoc +++ b/docs/content/guide/migration.ngdoc @@ -1230,10 +1230,7 @@ or simply use: - due to [a097aa95](https://github.com/angular/angular.js/commit/a097aa95b7c78beab6d1b7d521c25f7d9d7843d9), the default orderBy comparator sorts null values (strings, objects, etc.) as if they were the string `'null'`: - a null string will be sorted as if it started with the letter N. To sort nonexistent items to the last (or first, - if sort order is reversed) positions in the sort results, the sort predicate should use the empty string instead - of null. Similarly, predicate values that are `undefined` will be sorted as if they were strings starting with - the letter U. + a null string will be sorted as if it started with the letter N. diff --git a/src/ng/filter/orderBy.js b/src/ng/filter/orderBy.js index cf32e2dbcf7a..6b84d9cf2624 100644 --- a/src/ng/filter/orderBy.js +++ b/src/ng/filter/orderBy.js @@ -86,9 +86,8 @@ * * **Note:** If you notice numbers not being sorted as expected, make sure they are actually being * saved as numbers and not strings. - * **Note:** If null or undefined values are not being sorted as expected, convert them to the empty - * string before sorting. This is because of rule number 1 above which sorts `null` as `'null'` - * and `undefined` as `'undefined'`. + * **Note:** If null values are not being sorted as expected it may be due to rule number + * 1 above which sorts `null` as the string `'null'`. * * @param {Array|ArrayLike} collection - The collection (array or array-like object) to sort. * @param {(Function|string|Array.)=} expression - A predicate (or list of From 92f1586b21f23b46ceb6bdedf74ffb0e18198632 Mon Sep 17 00:00:00 2001 From: Allan Watson Date: Sat, 22 Oct 2016 12:06:35 -0400 Subject: [PATCH 3/3] Further wording updates. --- docs/content/guide/migration.ngdoc | 3 +-- src/ng/filter/orderBy.js | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/content/guide/migration.ngdoc b/docs/content/guide/migration.ngdoc index c2494d1c1970..cf28bbb8f907 100644 --- a/docs/content/guide/migration.ngdoc +++ b/docs/content/guide/migration.ngdoc @@ -1229,8 +1229,7 @@ or simply use: ### Filters (`orderBy`) - due to [a097aa95](https://github.com/angular/angular.js/commit/a097aa95b7c78beab6d1b7d521c25f7d9d7843d9), - the default orderBy comparator sorts null values (strings, objects, etc.) as if they were the string `'null'`: - a null string will be sorted as if it started with the letter N. + the default orderBy comparator now treats null values as the string 'null' diff --git a/src/ng/filter/orderBy.js b/src/ng/filter/orderBy.js index 6b84d9cf2624..c2f1a7da3906 100644 --- a/src/ng/filter/orderBy.js +++ b/src/ng/filter/orderBy.js @@ -86,8 +86,8 @@ * * **Note:** If you notice numbers not being sorted as expected, make sure they are actually being * saved as numbers and not strings. - * **Note:** If null values are not being sorted as expected it may be due to rule number - * 1 above which sorts `null` as the string `'null'`. + * **Note:** The above algorithm converts `null` values (normally of type `object`) to the string + * `'null'` (so has type `string`). This may cause unexpected sort order. * * @param {Array|ArrayLike} collection - The collection (array or array-like object) to sort. * @param {(Function|string|Array.)=} expression - A predicate (or list of