Don't sort the Map when using ngFor Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How to iterate using ngFor loop Map containing key as string and values as map iterationInfinite loop with javascript (Angular NgFor and http request)ngFor with index as value in attributeAngular 2 - *ngFor : Is there a way to use an alternative end condition?*ngFor with two way binding in IONIC 2Parsing a nested JSON in ngFor when the keys are unknownANGULAR 2/4 : call function for each row in NgForDynamic style css font-size ngFor angular 4 ionic 3How to get a reference to the list in an ngfor with a pipe applied to itAngular *ngFor item changesionic storage ngFor

Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?

How does light 'choose' between wave and particle behaviour?

Question about debouncing - delay of state change

What do you call the main part of a joke?

Using audio cues to encourage good posture

Is there a kind of relay only consumes power when switching?

How often does castling occur in grandmaster games?

Selecting user stories during sprint planning

How does the math work when buying airline miles?

Is CEO the "profession" with the most psychopaths?

Is it possible for SQL statements to execute concurrently within a single session in SQL Server?

How much damage would a cupful of neutron star matter do to the Earth?

What would you call this weird metallic apparatus that allows you to lift people?

How could we fake a moon landing now?

Dating a Former Employee

What is the topology associated with the algebras for the ultrafilter monad?

Denied boarding although I have proper visa and documentation. To whom should I make a complaint?

Most bit efficient text communication method?

Is it ethical to give a final exam after the professor has quit before teaching the remaining chapters of the course?

What initially awakened the Balrog?

ArcGIS Pro Python arcpy.CreatePersonalGDB_management

Why wasn't DOSKEY integrated with COMMAND.COM?

Is there hard evidence that the grant peer review system performs significantly better than random?

How fail-safe is nr as stop bytes?



Don't sort the Map when using ngFor



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How to iterate using ngFor loop Map containing key as string and values as map iterationInfinite loop with javascript (Angular NgFor and http request)ngFor with index as value in attributeAngular 2 - *ngFor : Is there a way to use an alternative end condition?*ngFor with two way binding in IONIC 2Parsing a nested JSON in ngFor when the keys are unknownANGULAR 2/4 : call function for each row in NgForDynamic style css font-size ngFor angular 4 ionic 3How to get a reference to the list in an ngfor with a pipe applied to itAngular *ngFor item changesionic storage ngFor



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am using ngFor to display a Map. To do so, I am using the keyvalue. It looks like this:



*ngFor="let upgrade of upgrades | keyvalue"


My Problem now is, that keyvalue sorts my Map. I don't want this and don't know how to stop the sorting.



I tried using sortOrder = (a): number => return (a); as compareFn; it worked, but I don't think that this is the corret way of doing it?










share|improve this question



















  • 1





    This might be sidetracking, but, what is wrong with actually sorting the info? Usually that makes it nicer for the end user's view :)

    – Alejandro Vales
    Mar 8 at 22:17


















0















I am using ngFor to display a Map. To do so, I am using the keyvalue. It looks like this:



*ngFor="let upgrade of upgrades | keyvalue"


My Problem now is, that keyvalue sorts my Map. I don't want this and don't know how to stop the sorting.



I tried using sortOrder = (a): number => return (a); as compareFn; it worked, but I don't think that this is the corret way of doing it?










share|improve this question



















  • 1





    This might be sidetracking, but, what is wrong with actually sorting the info? Usually that makes it nicer for the end user's view :)

    – Alejandro Vales
    Mar 8 at 22:17














0












0








0








I am using ngFor to display a Map. To do so, I am using the keyvalue. It looks like this:



*ngFor="let upgrade of upgrades | keyvalue"


My Problem now is, that keyvalue sorts my Map. I don't want this and don't know how to stop the sorting.



I tried using sortOrder = (a): number => return (a); as compareFn; it worked, but I don't think that this is the corret way of doing it?










share|improve this question
















I am using ngFor to display a Map. To do so, I am using the keyvalue. It looks like this:



*ngFor="let upgrade of upgrades | keyvalue"


My Problem now is, that keyvalue sorts my Map. I don't want this and don't know how to stop the sorting.



I tried using sortOrder = (a): number => return (a); as compareFn; it worked, but I don't think that this is the corret way of doing it?







angular ionic-framework ionic4






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 22:09









georgeawg

35k115470




35k115470










asked Mar 8 at 20:13









foo.doofoo.doo

15




15







  • 1





    This might be sidetracking, but, what is wrong with actually sorting the info? Usually that makes it nicer for the end user's view :)

    – Alejandro Vales
    Mar 8 at 22:17













  • 1





    This might be sidetracking, but, what is wrong with actually sorting the info? Usually that makes it nicer for the end user's view :)

    – Alejandro Vales
    Mar 8 at 22:17








1




1





This might be sidetracking, but, what is wrong with actually sorting the info? Usually that makes it nicer for the end user's view :)

– Alejandro Vales
Mar 8 at 22:17






This might be sidetracking, but, what is wrong with actually sorting the info? Usually that makes it nicer for the end user's view :)

– Alejandro Vales
Mar 8 at 22:17













2 Answers
2






active

oldest

votes


















0














since you are working with Map, If you do not want to sort the key
you can use



*ngFor="let key of upgrades.keys()"


or



 *ngFor="let entry of upgrades.entries()"


if you still want to use keyvalue pipe, your way is the right way. although it's a little confusing.
Since compareFn return a number, your sortOrder function will probably understand as null or NaN. I prefer (a,b)=>1 to be more clear. But it does not matter, the sorting is still happening, and probably waste some CPU time.






share|improve this answer

























  • I did actually see that attempt here: link. But, as mentioned there, this doesn't work.

    – foo.doo
    Mar 9 at 1:11












  • Surprised to see that does not work, but good to know. Thanks.

    – Haijin
    Mar 9 at 2:34


















0














Yes, the keyvalue pipe does sort by the keys. I suspect this was a requirement for ngClass and ngStyle, because this was mentioned in the source code comments.



You can't stop the sorting. I'd just create my own pipe.



@Pipe(name: 'entries', pure: true)
export class EntriesPipe implements PipeTransform
transform(value: May<any,any>)
return Array.from(value.entries());




I made the pipe pure, but that's up to you. It's difficult to work with Map<> types if it's pure.






share|improve this answer























  • Sidenote: although this will work, you will lose some of the optimizations that the keyvalue pipe has github.com/angular/angular/blob/7.2.8/packages/common/src/pipes/…

    – Jota.Toledo
    Mar 9 at 8:19











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070393%2fdont-sort-the-map-when-using-ngfor%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














since you are working with Map, If you do not want to sort the key
you can use



*ngFor="let key of upgrades.keys()"


or



 *ngFor="let entry of upgrades.entries()"


if you still want to use keyvalue pipe, your way is the right way. although it's a little confusing.
Since compareFn return a number, your sortOrder function will probably understand as null or NaN. I prefer (a,b)=>1 to be more clear. But it does not matter, the sorting is still happening, and probably waste some CPU time.






share|improve this answer

























  • I did actually see that attempt here: link. But, as mentioned there, this doesn't work.

    – foo.doo
    Mar 9 at 1:11












  • Surprised to see that does not work, but good to know. Thanks.

    – Haijin
    Mar 9 at 2:34















0














since you are working with Map, If you do not want to sort the key
you can use



*ngFor="let key of upgrades.keys()"


or



 *ngFor="let entry of upgrades.entries()"


if you still want to use keyvalue pipe, your way is the right way. although it's a little confusing.
Since compareFn return a number, your sortOrder function will probably understand as null or NaN. I prefer (a,b)=>1 to be more clear. But it does not matter, the sorting is still happening, and probably waste some CPU time.






share|improve this answer

























  • I did actually see that attempt here: link. But, as mentioned there, this doesn't work.

    – foo.doo
    Mar 9 at 1:11












  • Surprised to see that does not work, but good to know. Thanks.

    – Haijin
    Mar 9 at 2:34













0












0








0







since you are working with Map, If you do not want to sort the key
you can use



*ngFor="let key of upgrades.keys()"


or



 *ngFor="let entry of upgrades.entries()"


if you still want to use keyvalue pipe, your way is the right way. although it's a little confusing.
Since compareFn return a number, your sortOrder function will probably understand as null or NaN. I prefer (a,b)=>1 to be more clear. But it does not matter, the sorting is still happening, and probably waste some CPU time.






share|improve this answer















since you are working with Map, If you do not want to sort the key
you can use



*ngFor="let key of upgrades.keys()"


or



 *ngFor="let entry of upgrades.entries()"


if you still want to use keyvalue pipe, your way is the right way. although it's a little confusing.
Since compareFn return a number, your sortOrder function will probably understand as null or NaN. I prefer (a,b)=>1 to be more clear. But it does not matter, the sorting is still happening, and probably waste some CPU time.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 8 at 23:04

























answered Mar 8 at 22:57









HaijinHaijin

1,2161619




1,2161619












  • I did actually see that attempt here: link. But, as mentioned there, this doesn't work.

    – foo.doo
    Mar 9 at 1:11












  • Surprised to see that does not work, but good to know. Thanks.

    – Haijin
    Mar 9 at 2:34

















  • I did actually see that attempt here: link. But, as mentioned there, this doesn't work.

    – foo.doo
    Mar 9 at 1:11












  • Surprised to see that does not work, but good to know. Thanks.

    – Haijin
    Mar 9 at 2:34
















I did actually see that attempt here: link. But, as mentioned there, this doesn't work.

– foo.doo
Mar 9 at 1:11






I did actually see that attempt here: link. But, as mentioned there, this doesn't work.

– foo.doo
Mar 9 at 1:11














Surprised to see that does not work, but good to know. Thanks.

– Haijin
Mar 9 at 2:34





Surprised to see that does not work, but good to know. Thanks.

– Haijin
Mar 9 at 2:34













0














Yes, the keyvalue pipe does sort by the keys. I suspect this was a requirement for ngClass and ngStyle, because this was mentioned in the source code comments.



You can't stop the sorting. I'd just create my own pipe.



@Pipe(name: 'entries', pure: true)
export class EntriesPipe implements PipeTransform
transform(value: May<any,any>)
return Array.from(value.entries());




I made the pipe pure, but that's up to you. It's difficult to work with Map<> types if it's pure.






share|improve this answer























  • Sidenote: although this will work, you will lose some of the optimizations that the keyvalue pipe has github.com/angular/angular/blob/7.2.8/packages/common/src/pipes/…

    – Jota.Toledo
    Mar 9 at 8:19















0














Yes, the keyvalue pipe does sort by the keys. I suspect this was a requirement for ngClass and ngStyle, because this was mentioned in the source code comments.



You can't stop the sorting. I'd just create my own pipe.



@Pipe(name: 'entries', pure: true)
export class EntriesPipe implements PipeTransform
transform(value: May<any,any>)
return Array.from(value.entries());




I made the pipe pure, but that's up to you. It's difficult to work with Map<> types if it's pure.






share|improve this answer























  • Sidenote: although this will work, you will lose some of the optimizations that the keyvalue pipe has github.com/angular/angular/blob/7.2.8/packages/common/src/pipes/…

    – Jota.Toledo
    Mar 9 at 8:19













0












0








0







Yes, the keyvalue pipe does sort by the keys. I suspect this was a requirement for ngClass and ngStyle, because this was mentioned in the source code comments.



You can't stop the sorting. I'd just create my own pipe.



@Pipe(name: 'entries', pure: true)
export class EntriesPipe implements PipeTransform
transform(value: May<any,any>)
return Array.from(value.entries());




I made the pipe pure, but that's up to you. It's difficult to work with Map<> types if it's pure.






share|improve this answer













Yes, the keyvalue pipe does sort by the keys. I suspect this was a requirement for ngClass and ngStyle, because this was mentioned in the source code comments.



You can't stop the sorting. I'd just create my own pipe.



@Pipe(name: 'entries', pure: true)
export class EntriesPipe implements PipeTransform
transform(value: May<any,any>)
return Array.from(value.entries());




I made the pipe pure, but that's up to you. It's difficult to work with Map<> types if it's pure.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 9 at 2:15









cgTagcgTag

24.7k865114




24.7k865114












  • Sidenote: although this will work, you will lose some of the optimizations that the keyvalue pipe has github.com/angular/angular/blob/7.2.8/packages/common/src/pipes/…

    – Jota.Toledo
    Mar 9 at 8:19

















  • Sidenote: although this will work, you will lose some of the optimizations that the keyvalue pipe has github.com/angular/angular/blob/7.2.8/packages/common/src/pipes/…

    – Jota.Toledo
    Mar 9 at 8:19
















Sidenote: although this will work, you will lose some of the optimizations that the keyvalue pipe has github.com/angular/angular/blob/7.2.8/packages/common/src/pipes/…

– Jota.Toledo
Mar 9 at 8:19





Sidenote: although this will work, you will lose some of the optimizations that the keyvalue pipe has github.com/angular/angular/blob/7.2.8/packages/common/src/pipes/…

– Jota.Toledo
Mar 9 at 8:19

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070393%2fdont-sort-the-map-when-using-ngfor%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved