honestbleeps / Reddit-Enhancement-Suite

Reddit Enhancement Suite
http://redditenhancementsuite.com
GNU General Public License v3.0
4.16k stars 878 forks source link

Sort table by numbers not working properly #4331

Open ghost opened 7 years ago

ghost commented 7 years ago

What's the problem? Table doesn't sort by numbers properly. For example, if I have a table with 9,000,000, 80,000,000, and 7,000,000, the order will either be 7,000,000, 80,000,000, 9,000,000 or 9,000,000, 80,000,000, 7,000,000. I discovered this when making my own table in this Reddit post.

Are there any related posts in https://github.com/honestbleeps/Reddit-Enhancement-Suite/issues or /r/RESissues? No.

What other browser extensions are installed? Adblock Plus Dark YouTube Theme Greasemonkey Instant Translate: Select and Translate MEGA uBlock Origin Video DownloadHelper

njvorwerck commented 7 years ago

It's treating the numbers as strings and comparing them lexicographically. A fix would be checking to see if the column has numeric values. If it does, convert them to a numeric type and sort. (I'm not going to do it, I just stumbled upon this page and thought I'd offer my 2 cents)

mikeparas commented 7 years ago

I was just looking into this, and the code already does what @njvorwerck suggests. The sorting function checks if the cell contains a numeric value using jQuery.isNumeric. However, in the post @airatin links to, his numbers contain commas, and isNumeric apparently does not consider that numeric.

It would be easy enough to accommodate this case, but are there other cases that should be considered? Money comes to mind (e.g. '$1.99'), but there are probably others that I'm not thinking of.