Page MenuHomePhabricator

Sortable tables don't properly sort lists of names
Closed, ResolvedPublic


Author: gabriel.fishman

Great work on the sortable tables javascript!
When the javascript is applied to tables with a column that is a list of names
(e.g. a table of US Senators with a column for the name, state, year elected,
etc.) the script will sort by first name rather than last name, which is
generally the wrong behavior. I would love to see a solution where a user could
define a parameter for a particular column which would tell MediaWiki to sort
that column lexicographically starting with the first letter of the last word in
each cell (the last name). Perhaps this could be achieved by adding an html
comment such as <!--LNAME--> to the first cell in the column.

This is my first bug report so I apologize if its formatted incorrectly. :)

Version: unspecified
Severity: enhancement
OS: Mac OS X 10.4



Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 9:32 PM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz8288.
bzimport added a subscriber: Unknown Object (MLST).

leon wrote:

AFAIK, Brion is gonna remove sortable tables.

ayg wrote:

Currently the implementation of sortable tables is very unobtrusive HTML-wise
(just a class), which makes it trivial to implement. Allowing some kinds of
comments, which are currently stripped by the parser, is a nontrivial task, and
possibly a dangerous one since IE can (by design!) be persuaded to execute
arbitrary HTML inside them. Probably more sensible would be to uniquely ID all
the rows and have some kind of one-line <script> tag for each that would give
its sort key, but again, that would require Parser changes and could be dangerous.

The only easy and non-dangerous thing I could think of would be to abuse the
class attribute, but that's pretty hacky. Not as hacky as inexpertly matching a
sort key to the background color and putting it at the beginning of the cell,
though . . .

(In reply to comment #1)

AFAIK, Brion is gonna remove sortable tables.

I'm pretty sure he wasn't serious.

jwillbur wrote:

Incidently, GabrielF's suggestion to sort by the first letter of the last word in
each cell (the last name) does not take into account two (or more) word names.
For example, "John Van Dyke" would be sorted by "Dyke", while it should sort by
"Van Dyke". Having the user explicitly give a sort key for each cell would work

Here are ideas how this could be accomplished:

  1. One could add a column to the table with a class that inhibits its

rendering, and needs a link to the column it is providing a sort key
for. Imho that is too complcated because of the link, and will display
the sort key column in CSS-unaware browsers, and requires editors to add
another columns with proper CSS class for each cell.

  1. Add an attibute to <td>s such as <td sortkey="van Dam, Joseph P. Anthony">

for cells needing one. It is ignored by html browsers, but the sorting
(java)script could use them, and only resort to the cell content, if
there is no sortkey attribute for a cell. This makes sorting slower, but
since tables tend not to be excessively huge, that should be acceptable.

, provided, we add tables for them to the data base, and create
these parser functions, which is pretty trivial with the appropriate
data base fields.

Use data-sort-value="van Dam"