Skip to content

Pipe "keyvalue" should not sort by default. #42490

@y0nd0

Description

@y0nd0

Issue / 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: commonIssues related to APIs in the @angular/common packagebreaking changesfeatureIssue that requests a new featurefeature: under considerationFeature request for which voting has completed and the request is now under consideration

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions