Correct number order in dictionary

Hello, I’m getting some data from firebase but the numerical order is not correct.

I’m getting the order n1, n10, n11, n2, n3, n4…
I would like to arrange n1, n2, n3, n4, n5…

Screenshot_1

Use @yuchain_chang listaddon extension
(Try either bubble sort or simple sort) simple

1 Like

Dictionaries (in general) are designed for storing key/value mappings, they don’t have an “order”, so even if you try to order keys, when you add a new key to the dictionary later, there is no guarantee that the key/value will be added to last, it is totally up to App Inventor. (Not sure how App Inventor handles dictionaries, but still, don’t rely on order)

If you want to rely on order, consider using a list instead, which is guaranteed that its order won’t alter because it is indexed on position.

Well, you can order the keys only, but not sure what you want to achieve.

1 Like

unfortunately it didn’t work

I’m doing it as follows

1-here I get the click id and save it again in firebase.

2-here I get the values ​​and add them to a list, but since it comes in the wrong order, it’s always in the wrong order when I put it in the view.

3-here are the values ​​corresponding to the list in the wrong order.

4- structure on fb
Screenshot_5

everything is working fine, except for separating the values ​​in the correct order.
I will be grateful for any help

Yeah noted… Not working… But dont worry. Already @juananton1991 Juan_Antonio gave his wounderful javascript extension. No need to use web view

see how i have tried

FB structure
image

so work simple

For extension click here

Summary

[Free] Evaluate JavaScript Extension. Math expression. Source code - Extensions - MIT App Inventor Community

The JS code

Summary

[Your_Keys_Goes_here_within_this_bracket].sort((a, b) => { return a.toString().localeCompare(b.toString(), ‘en’, { numeric: true }) })

My App Response

1 Like

thank you very much for your valuable help, it saved me I tried for 2 days to solve it myself but without success.

1 Like

Please Visit our community and keep posting query like this… Really we have to thank the extension developer
@juananton1991 @Profile - Juan_Antonio - MIT App Inventor Community for making our work simple… I think he is not in kodular but Power user in MIT App

Edit: Sorry, he is available at @juananton1991 , alias called as Kio4

1 Like