Page MenuHomePhabricator

improved table sorting of decimal numbers
Closed, ResolvedPublic

Description

Author: eran_roz

Description:
Recently a new option of sortable tables was added, but the sorting script
doesn't sort properly numbers with commas (like 12,000). an example:
{| class="sortable"

numbers
-
12
-
8
-
9
-
8.000
}

and the results (from bigger to smaller number): "12", "9", "8", "8,000", and of
course it should be: "8,000", "12", "9", "8".

It should be noticed that the script works fine with dots (like 8.532). I'm
almost sure that the reason for this bug is wrong recognizing of numbers with
commas as strings, and not as numbers.
Maybe it can be fixed in sorttable.js by changing the line:
"if (itm.match(/^\s*[\d\.]+\s*$/)) sortfn = ts_sort_numeric;"
to
"if (itm.match(/^\s*[\d\.\,]+\s*$/)) sortfn = ts_sort_numeric;"


Version: unspecified
Severity: normal

Details

Reference
bz8115

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:34 PM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz8115.

Should this not also be subject to localisation? In some locales, the "decimal point"
is represented by a period and the "thousand separator" by a comma; in others it is
the other way around.

robchur wrote:

(In reply to comment #1)

Should this not also be subject to localisation? In some locales, the "decimal

point"

is represented by a period and the "thousand separator" by a comma; in others

it is

the other way around.

That's bug 8063. We could argue that this is a duplicate.

cohesion wrote:

This is a problem with any non-numeric character, including negative numbers
with "-". Some discussion here http://blog.webkist.com/archives/000043.html

jackdt wrote:

"It should be noticed that the script works fine with dots (like 8.532)"

It doesn't always - see
http://en.wikipedia.org/w/index.php?title=List_of_countries_by_murder_rate&oldid=92298115
and click 1995's sorting arrow once, scroll down, and you'll see it's correctly
sorted. Click 1995's sorting arrow a second time and it now incorrectly sorts
the reals like strings: ... 7.12, 68.09, 6.85 ... instead of 68.09, 57.91 ...
7.12, 6.85 ...

patrick.wikipedia wrote:

That has been fixed now, but see
http://meta.wikimedia.org/wiki/Help_talk:Sorting for
some more modifications, that allow numbers with commas
or spaces as thousands separators, and in scientific
notation.

It also allows links in headers, by adding the HTML for
the sort button to the existing HTML instead of to the
inner text. That seems to work fine in the simple cases
that I have tried.

patrick.wikipedia wrote:

It is helpful that a comma in a number is now allowed
as thousands separator, but please allow also multiple
commas.

Also, please allow negative numbers.

See http://meta.wikimedia.org/w/index.php?
title=MediaWiki:Common.js&oldid=562970

Fixed in upcoming jQuery version

r86088 is seriously broken and may get reverted; reopening. Needs unit tests (see initial basic unit tests in r90595 which show up errors; will also need tests for the particular case this bug is about.)

Assigning bug from DieBuche to me. Will check QUnit tests and write missing one.

Added some tests with r105560

Need to find out how to change the locale to redo the same tests with a different language.

This appears to be fixed. If there's a task associated with this that needs to be fixed, that should be a separate bug.