Leading Zeros #6

Mottie opened this Issue Aug 6, 2012 · 2 comments


None yet

2 participants

Mottie commented Aug 6, 2012

Hi, I've been using your Natural Sort to replace the sorting algorithm in my fork of jQuery tablesorter

But if you check out the first column of this demo you'll see that A02 and A012 don't sort correctly

I've found that if I change line 29 & 30 to the following, it works properly:

oFxNcL = isNaN(xN[cLoc]) ? xN[cLoc] || 0 : parseFloat(xN[cLoc]) || 0;
oFyNcL = isNaN(yN[cLoc]) ? yN[cLoc] || 0 : parseFloat(yN[cLoc]) || 0;

Edit: here is a simplified version : http://jsfiddle.net/Mottie/LannP/

overset commented Aug 7, 2012

Thanks for catching this! I can definitely see use cases with 0 left padded numbers that start with another character. I just did a quick test with your changes against the existing the unit-tests.html and it's breaking a couple of other sorts that should work. Let me try and go off your A02 and A012 example, build a few test cases and see if I can get something to work for all the test cases. On that note - have any other ideas on what I can ensure this will sort properly so I can build some more test cases..?


@overset overset was assigned Aug 7, 2012
Mottie commented Aug 7, 2012

DOH, I forgot to check the unit tests! I haven't run into any other cases that don't work correctly, but I'll be sure to post an issue if I do run into any.

@overset overset added a commit that referenced this issue May 4, 2015
@overset fixes for #6 #7 #16 #18 + more tests eaee858
@Mottie Mottie closed this Sep 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment