question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pipe "keyvalue" should not sort by default.

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:58
  • Comments:29 (20 by maintainers)

github_iconTop GitHub Comments

7reactions
petebacondarwincommented, Sep 16, 2021

I think that semantically:

  • undefined -> do the default sort
  • null -> do no sorting

works 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.

3reactions
petebacondarwincommented, Sep 16, 2021

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable the default keyvalue pipe sort in angular
I am just trying to print the items in the regular order but the key/value pipe does a default sorting based on the...
Read more >
Angular keyvalue Sorting & Variation of *ngFor directive
According to the Angular documentation, the keyvalue pipe sorts the items by key order by default. You can provide a compare function to ......
Read more >
Angular KeyValue Pipe - TekTutorialsHub
Default Sorting. KeyValue pipe uses the key to sort the results array. You can see it from the above example. Even though our...
Read more >
KeyValuePipe - Angular
Transforms Object or Map into an array of key value pairs. ... show how an Object or a Map can be iterated by...
Read more >
angular keyvalue pipe sort properties / iterate in order-angular.js
According to the Angular documentation, the keyvalue pipe sorts the items by key order by default. You can provide a comparer function to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found