-
Notifications
You must be signed in to change notification settings - Fork 27.4k
docs(orderBy): Clarify behavior of default comparator #15304
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this applies to |
||
the letter U. | ||
|
||
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What this note should mention is that I would also refrain from suggesting any work arounds, because there are different ones available, each with its pros and cons (e.g. use an extra predicate to separate null from non-null value, convert There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed as suggested. |
||
* 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.<Function|string>)=} expression - A predicate (or list of | ||
|
There was a problem hiding this comment.
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
:)There was a problem hiding this comment.
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.