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

docs(orderBy): Clarify behavior of default comparator #15304

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/content/guide/migration.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,13 @@ 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'`:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null values can't be strings, objects etc. A null value is just null :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm...actually things are a little more complicated: #15293 (comment)

For this breaking change note, you need to mention the change introduced in a097aa9.
For the docs, you need to mention the current situation, as introduced in 48e1f56.

a null string will be sorted as if it started with the letter N.





Expand Down
2 changes: 2 additions & 0 deletions src/ng/filter/orderBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +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'`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is not related to rule number 1. Normally, the type of null is object. But we sort it as if it's type were string.

I would write something like:

Note: Normally the type of null is object. When applying the above algorithm, null values are converted to the string 'null' (and thus have a type of string).

*
* @param {Array|ArrayLike} collection - The collection (array or array-like object) to sort.
* @param {(Function|string|Array.<Function|string>)=} expression - A predicate (or list of
Expand Down