Pipe "keyvalue" should not sort by default.
See original GitHub issueIssue / Improvement / Feature Request
Relevant Package
@angular/common
(source)
Description
Currently the keyvalue
pipe sorts the keys. This result in e.g.
1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, ...
Because it’s not natual sorted. …
Describe the solution you’d like
It should not sort by default. Respect the original object state.
It’s annoying to declare a no sort method to each component which uses keyvalue. (function that returns 0
for no sort.)
Describe alternatives you’ve considered
Provide predefined sort functions. The parameter of keyvalue
could be a string or function. The string is the name of the predefined buildin function of Angular. Like:
keyvalue: 'natural'
keyvalue: 'sort' // the current sort behavior
keyvalue: mySort // a custom function
keyvalue // default no parameter, no sort.
Or we could invert the logic so that no parameter means the current behvaior but keyvalue: 'none'
disables the sort. For downwards compatibility. If you care about. But in my opinion we should ignore that. A tiny breaking change. The migration is simple: Just add 'sort'
to the keyvalue pipe. So I still prefer my solution: Don’t sort by default.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:58
- Comments:29 (20 by maintainers)
Top GitHub Comments
I think that semantically:
undefined
-> do the default sortnull
-> do no sortingworks for me.
I feel that this is the right first step. Then we can look into making no sort the default and how we would migrate people who want the current default sort.
And to avoid confusion, I think that this issue better captures what we want to achieve. So I am actually going to reopen this issue and close the other one!