Skip to content
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

Leading zeros are ignored when sorting text columns #409

Closed
rbirkby opened this issue Nov 6, 2013 · 6 comments
Closed

Leading zeros are ignored when sorting text columns #409

rbirkby opened this issue Nov 6, 2013 · 6 comments

Comments

@rbirkby
Copy link

rbirkby commented Nov 6, 2013

A text column is being sorted as follows:

1
2
3
00004
4
5
6
7
8
9

See http://jsfiddle.net/rbirkby/HQ7mg/4/

I would expect the 00004 value to be ordered first.
This is not what I would expect, nor is it how JavaScript will sort.

@Mottie
Copy link
Owner

Mottie commented Nov 6, 2013

The default text sorter is the natural sort, which behaves like a numerical sort, but is slightly slower than a straight numerical sort. Instead set the textSorter to the basic text sort (demo):

$(function() {
    $("table").tablesorter({
        textSorter: {
            0: $.tablesorter.sortText
        }
    });
});

@thezoggy
Copy link
Collaborator

thezoggy commented Nov 6, 2013

funny i was just creating an example to show this: http://jsfiddle.net/4mVfu/1131/

@Mottie
Copy link
Owner

Mottie commented Nov 6, 2013

Hehe, thanks :P

The $.tablesorter.sortText function is exactly the same as you have (ref):

// basic alphabetical sort
ts.sortText = function(a, b) {
    return a > b ? 1 : (a < b ? -1 : 0);
};

@rbirkby
Copy link
Author

rbirkby commented Nov 6, 2013

Thanks for explaining this. I spent a while reading the docs but couldn't find what I was looking for and even now I know what to look for I can't find documentation on sortNatural and sortText.

Thanks again

@Mottie
Copy link
Owner

Mottie commented Nov 6, 2013

I guess it's not that obvious... look at the last code block under the textSorter option.

@Mottie
Copy link
Owner

Mottie commented Nov 20, 2013

@rbirkby By the way, in the latest update, I've added a search feature to the main page. Just click on the icon in the upper left corner.

So now that I think this issue has been fully resolved, I'm going to close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants