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
Comments
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? |
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. |
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. |
Could you come up with some html demonstrating the issue? Thanks! |
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.
|
The behavior is explained by these lines: Stupid-Table-Plugin/stupidtable.js Lines 35 to 39 in 3113e84
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. |
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. |
Case-insensitive sorting has been added and merged into master. |
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
The text was updated successfully, but these errors were encountered: