stevegreatrex / ko.plus

Awesome extensions to KnockoutJS
http://stevegreatrex.github.io/ko.plus
MIT License
34 stars 12 forks source link

sortBy with null values not sorting correctly? #9

Closed conficient closed 9 years ago

conficient commented 9 years ago

Any suggestion why I'm getting this behaviour using the sortBy binding?

The array contains plain JavaScript objects, and I am sorting on the date field, which is stored as a string. Some values contain a null (I have represented as [null] here) but it seems to corrupt the sorting. I would expect null values to either go at one end or the other, not in the middle!

raw date            Date    
------------------- ---------
2014-02-17T00:00:00 17-Feb-14   
2014-03-02T00:00:00 2-Mar-14    
[null]              --
[null]              --
2015-01-25T00:00:00 25-Jan-15   
2015-02-22T00:00:00 22-Feb-15   
2015-02-23T00:00:00 23-Feb-15   
2015-02-27T00:00:00 27-Feb-15   
2015-03-01T00:00:00 1-Mar-15    
2015-03-01T00:00:00 1-Mar-15    
2015-03-02T00:00:00 2-Mar-15    
2015-03-02T00:00:00 2-Mar-15    
2015-03-02T00:00:00 2-Mar-15    
2015-03-02T00:00:00 2-Mar-15    
2015-03-02T00:00:00 2-Mar-15    
conficient commented 9 years ago

Just checked my version and it's 0.0.21 so it's current - I saw the recent commit relating to nulls.

I've been playing with the sort and it's actually worse than this, it's not even consistent - the blank entries shift around in the order each time I sort.

conficient commented 9 years ago

Created a Fiddle to demonstrate this: http://jsfiddle.net/Quango/zhe7nexg/9/

stevegreatrex commented 9 years ago

Thanks @conficient. Check out this updated fiddle

I'll push out a new version later (assuming all ok!)

conficient commented 9 years ago

Thanks for the fast turn-around on a fix Steve. Looks fine to me.