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

Uppercase and Lowercase treated differently #46

Closed
GhostToast opened this issue Jan 25, 2013 · 8 comments
Closed

Uppercase and Lowercase treated differently #46

GhostToast opened this issue Jan 25, 2013 · 8 comments

Comments

@GhostToast
Copy link

I had some test sample data that was sorting erratically. Had many strings that were "fail" (purposefully), and other strings as well. The thing is, only "fail" sample data was in lowercase, and they were always blocked together away from other strings, but not in true alphabetical order. I can override this with a simple strtoupper() for my data-sort-value. Just thought I'd post this in case it was an issue elsewhere. Here is some sample output without stringtoupper() in place:

Date Name Price
01/15/2013 2013 Membership $100.00
01/15/2013 2013 Membership $100.00
01/15/2013 2013 Membership $1.00
01/17/2013 2014 Membership $999.00
01/10/2013 A Test $250
01/22/2013 Event Registration Test $10.00
01/10/2013 Fail $1
01/10/2013 Fail $1
01/10/2013 Fail $1
01/10/2013 Fail $1
01/31/2013 THis IS A TEST $125
01/10/2013 The first one $1551
01/10/2013 The first one $1251
01/18/2020 The future payment of the future $10000000
01/10/2013 fail $666
01/10/2013 fail $123
01/10/2013 fail $1
01/10/2013 fail $1
01/10/2013 fail $1

@GhostToast
Copy link
Author

I see you are already aware of this. Now I have a new question: What is more expensive? To have PHP change the case of the string for the sort? Or to have the function referenced here?
https://github.com/joequery/Stupid-Table-Plugin/wiki/Sorting-functions

@joequery
Copy link
Owner

It all depends on how much you care about the presentation. If you want a faster sort and don't care about presentation, lowercase on the server. If you care about presentation (names, for example), just use the string-ins sort.

I'm still open to the idea of changing the default behavior. I was under the assumption that programmers would assume sorts would be based on ASCII, but perhaps that assumption was wrong.

@GhostToast
Copy link
Author

Well I suppose the use-case will determine how important it is that things be be sorted by strict alphabetization or not. Even in my example, it is very unlikely that real data will end up with lower-case strings. But since users are ultimately inputting data, I do want to sort this in a way that I predict they will expect, even if I am not so concerned about sanitizing the output string (they need to realize at SOME point they have done something strange). Thanks for your response, and work on this plugin.

I also want to point out that I had a mixed bag on floats and ints together in one column, being treated as floats. The sort behavior was unidirectional only (but did work). Would only sort from low to high. There were several values of "1" and some with "1.00". The first click would sort them numerically by true value, leaving the "1.00" values inline with the "1"s. The second click would filter the "1.00" results to the bottom of the "1"s pile.

I simply used "round" on my data-sort and went back to integers, as there won't really be any values that actually contain decimals, most likely. Still, it was strange.

@joequery
Copy link
Owner

Could you come up with some html demonstrating the issue? Thanks!

@GhostToast
Copy link
Author

Here you go. This doesn't show unsorted as "view source" just displays what was originally there apparently. If you sort by something else like "Name" and then "Price" it will leave 1.00 inline with the rest of the 1. Sort by Price a second time and it filters 1.00 to the bottom of the 1 - it is as though they are being treated pretty differently.

<table class="payment_history_table">
    <thead>
        <tr>
            <th data-sort="int">Date</th>
            <th data-sort="string">Name</th>
            <th data-sort="float">Price</th>
        </tr>
    </thead>
    <tr>
        <td data-sort-value="1357776000">01/10/2013</td>
        <td data-sort-value="A Test">A Test</td>
        <td data-sort-value="250">$250</td>
    </tr>
    <tr>
        <td data-sort-value="1357776000">01/10/2013</td>
        <td data-sort-value="Fail">Fail</td>
        <td data-sort-value="1">$1</td>
    </tr>
    <tr>
        <td data-sort-value="1357776000">01/10/2013</td>
        <td data-sort-value="fail">fail</td>
        <td data-sort-value="666">$666</td>
    </tr>
    <tr>
        <td data-sort-value="1357776000">01/10/2013</td>
        <td data-sort-value="Fail">Fail</td>
        <td data-sort-value="1">$1</td>
    </tr>
    <tr>
        <td data-sort-value="1357776000">01/10/2013</td>
        <td data-sort-value="Fail">Fail</td>
        <td data-sort-value="1">$1</td>
    </tr>
    <tr>
        <td data-sort-value="1357776000">01/10/2013</td>
        <td data-sort-value="fail">fail</td>
        <td data-sort-value="123">$123</td>
    </tr>
    <tr>
        <td data-sort-value="1357776000">01/10/2013</td>
        <td data-sort-value="fail">fail</td>
        <td data-sort-value="1">$1</td>
    </tr>
    <tr>
        <td data-sort-value="1357776000">01/10/2013</td>
        <td data-sort-value="fail">fail</td>
        <td data-sort-value="1">$1</td>
    </tr>
    <tr>
        <td data-sort-value="1357776000">01/10/2013</td>
        <td data-sort-value="Fail">Fail</td>
        <td data-sort-value="1">$1</td>
    </tr>
    <tr>
        <td data-sort-value="1357776000">01/10/2013</td>
        <td data-sort-value="fail">fail</td>
        <td data-sort-value="1">$1</td>
    </tr>
    <tr>
        <td data-sort-value="1357776000">01/10/2013</td>
        <td data-sort-value="The first one">The first one</td>
        <td data-sort-value="1551">$1551</td>
    </tr>
    <tr>
        <td data-sort-value="1357776000">01/10/2013</td>
        <td data-sort-value="The first one">The first one</td>
        <td data-sort-value="1251">$1251</td>
    </tr>
    <tr>
        <td data-sort-value="1358208000">01/15/2013</td>
        <td data-sort-value="2013 Membership">2013 Membership</td>
        <td data-sort-value="100">$100.00</td>
    </tr>
    <tr>
        <td data-sort-value="1358208000">01/15/2013</td>
        <td data-sort-value="2013 Membership">2013 Membership</td>
        <td data-sort-value="100">$100.00</td>
    </tr>
    <tr>
        <td data-sort-value="1358208000">01/15/2013</td>
        <td data-sort-value="2013 Membership">2013 Membership</td>
        <td data-sort-value="1.00">$1.00</td>
    </tr>
    <tr>
        <td data-sort-value="1358380800">01/17/2013</td>
        <td data-sort-value="2014 Membership">2014 Membership</td>
        <td data-sort-value="999">$999.00</td>
    </tr>
    <tr>
        <td data-sort-value="1358812800">01/22/2013</td>
        <td data-sort-value="Event Registration Test">Event Registration Test</td>
        <td data-sort-value="10">$10.00</td>
    </tr>
    <tr>
        <td data-sort-value="1359590400">01/31/2013</td>
        <td data-sort-value="THis IS A TEST">THis IS A TEST</td>
        <td data-sort-value="125">$125</td>
    </tr>
    <tr>
        <td data-sort-value="1579305600">01/18/2020</td>
        <td data-sort-value="The future payment of the future">The future payment of the future</td>
        <td data-sort-value="10000000">$10000000</td>
    </tr>
</table>

@joequery
Copy link
Owner

The behavior is explained by these lines:

// If this index is already in the map, look for the next index.
// This handles the case of duplicate entries.
while($.inArray(index, map) != -1){
index++;
}

Basically in the event of equal values during the sort, which ever one appears first before the sort will appear first after the sort. So it's not actually related to data-sort-value at all, this behavior would be exhibited on any table using this plugin. Although I'm not sure how detrimental this behavior really is, I'm willing to fix it since it may confuse some users.

One possible fix is to implement a cache of sorts. We can try something simple, like keeping track of the column values the first time it is sorted and either return the array or the reverse of it instead of forcing the column through the sort every time. This may have some performance benefits as well, but very large table may take up too much memory. I'll need to test it.

@joequery
Copy link
Owner

In regards to the case insensitive sort, I'm opening discussion on issue #49. I'd like to keep the plugin as small as possible, but it seems as though a few issues have come up where people have expected case-insensitive sorting behavior as default. Perhaps the best thing I could do is give them a default sort.

@svivian
Copy link
Collaborator

svivian commented Apr 6, 2013

Case-insensitive sorting has been added and merged into master.

@svivian svivian closed this as completed Apr 6, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants