-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Numeric sort #980
Comments
First, if you prepend codes such that the length is always the same, string sorting will work. This means, use If you can't do that, I think the issue there is that the inputs are strings, and so the comparison uses string comparison. irb(main):004:0> Liquid::Template.parse("{{ a | sort }}").render("a" => [10, 2, 3])
=> "2310"
irb(main):005:0> Liquid::Template.parse("{{ a | sort }}").render("a" => ['10', '2', '3'])
=> "1023" There are some unreasonably complex ways of achieving this transformation: Liquid::Template.parse("{% for i in a %}{% assign wrapped = i | floor | compact %}{% assign b = b | concat: wrapped %}{% endfor %}{{ b | sort }}").render("a" => ['10','2','3'])
=> "2310" but we could consider adding a |
coming in late on this, but I have a similar issue with needing to sort by version numbers. say I have a list of version numbers like it would be great if a potential |
Hello chums, This is a real pain for us because it looks horrible! A |
This is worse than described here. I thought the values would always be treated as strings at least, but they're not. Values are always read as numbers and then converted to strings before sorting. Thus values with a leading "0" are read as octal numbers and invalid octal values won't be sorted correctly. So using If I want all values to be treated as strings I have to use quotes or a prefix different than "0" in every value. Examples that work:
|
This is really anoying while still not fixed and it doesn't work like written in docs. importance field = integer in Shopify metaobject value definition This is really important liquid functionality thats not working like expected and the docs say. Regards Spencer |
Still need it to sort metaobjects properly |
Chiming in here, it's pretty weird that sorting can't sort based on a numeric data type - that's 101 level functionality |
2: difficult Even Yoda can't get it right But seriously please we need this! I have to use javascript to sort right now. Seems crazy Thank you @spencer-j for confirming that metaobjects are completely broken. I was so confused. |
I am attempting to design a Shopify order template and need the orders to print in order (numerically) by product number. Unfortunately it ends up in this order:
01
07
104
13
I have also tried the "sort_natural" filter. Any suggestions? Is there a better filter/pipe? I can alter the product codes so there are no leading zeros, but that will not fix the three digit problem...
Thanks for any assistance.
The text was updated successfully, but these errors were encountered: