knockout-orderable icon indicating copy to clipboard operation
knockout-orderable copied to clipboard

Support for sorting numbers

Open iamdevman opened this issue 12 years ago • 6 comments

Added support for sorting numbers.

iamdevman avatar Apr 24 '13 03:04 iamdevman

It already supports sorting by numbers. See example here http://apuchkov.com/knockout-orderable/examples/basic.html Can you tell which specific use case you are trying to solve with this? Thanks

apuchkov avatar Apr 26 '13 02:04 apuchkov

It does in fact support number sorting, but not in all cases. As i can see, it sorts numbers "alphabetically". Meaning that all numbers starting with 9 will be before numbers starting with 8 etc.... depending on the sort order.

However, this has an issue when it comes to larger numbers such as my case (see image, column is sorted in descending order) : image

As you can see, the number 973676 should be out in first, before 99344, hence my comment on alphabetical ordering.

jonathanhallee avatar Jun 18 '13 16:06 jonathanhallee

And the code I committed will do a sort based on Numerical order, not alphabetical.

iamdevman avatar Jun 19 '13 12:06 iamdevman

Latest version sorts numbers correctly, see here http://jsfiddle.net/bqJZC/

apuchkov avatar Jun 24 '13 04:06 apuchkov

Don't think i was specific enough. Here is my case : http://jsfiddle.net/bqJZC/1/

Anyway, i've added the support for that case in my version of the code. Basically it just tries to parse into integer & adds support for undefined values.

jonathanhallee avatar Jun 25 '13 01:06 jonathanhallee

I see you store numbers as stings in your ViewModel, this is why it works differently. Will review your change and merge them in a bit later. Thanks

apuchkov avatar Jun 25 '13 17:06 apuchkov