Page MenuHomePhabricator

Provide a way to set the initial sort for sortable tables
Open, LowestPublicFeature

Description

Provide a mechanism to create pages with sorted tables, using a user provided column sort priority directive. Such sorting should occur server-side for consistency.


Currently there is no way to do this. It would be nice to make it possible to do a link to http://translatewiki.net/w/i.php?title=Special%3ALanguageStats&x=D&code=qqq where it is sorted by translation coverage by default.


See Also:
T17406: Sortable tables: Force sortorder of a column
T31266: link to sort order for a translation stats page

Details

Reference
bz31332

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:54 PM
bzimport set Reference to bz31332.
bzimport added a subscriber: Unknown Object (MLST).

When permalinks are wanted we usually let the table be built with the TablePager class, which provides server-side sortability for (single or multi-page) tables. It uses query parameters in the URL to trigger which column to sort and in which direction to sort it.

In JavaScript in general, and especially in jquery.tablesorter this would be kinda akward to implement. The problem starts at identifying which table is meant (since there can be multiple table.sortable elements on an article). Then how to identify which column ? Refer by number ?

Currently for the on-page state an incrementing number is used to differentiate between different tables etc. however these are only to be used within a state, not in URLs to new instances/loads of the article as the numbers are likely not the same (there could be an additional table, or tables re-ordered, merged, moved etc. there is no reliable ID.

Taking that the given example is a table outputted by a MediaWiki (PHP) extension, and not wikitext. Using TablePager (or a variation on it that allows GET parameters to handle the sorting) should be do-able.

Alternatively you could implement a few lines of JavaScript as part of the Translate-extension listening to a value in location.hash when the page is loaded and trigger a sort. Again, I suggest to do this inside the special page or extension instead of in jquery.tablesorter as jquery.tablesorter is primarily meant for articles and needs to support multiple tables per-page.

Something with $(document).ready, window.location.hash and $(find table) using $.fn.tablesorter or $.fn.click or $.fn.attr to somehow force an initial sort.

Moving from component ResourceLoader to JavaScript (related to the jquery.tablesorter module)

TablePager would be a significant detour how I generate the table currently, and I don't need most of the stuff it does, like paging.

Can't we just refer to the table with id/class?

skomorokh wrote:

It would be really nice to have a better way to do this. Conscientiously entering each row in alphabetical order is a bit more of an editing task. And the process to sort things afterwards seems to be rather more work than would be ideal:

http://meta.wikimedia.org/wiki/Help:Sorting#Default_order

Seems like this could save a lot of editors a lot of time they could instead devote to content.

FYI I implemented a custom solution for my special pages: http://translatewiki.net/w/i.php?title=Special:LanguageStats&suppresscomplete=1#sortable:2=desc

I'm withdrawing this request since there doesn't seem to be interest for generic solution.

Guarapiranga added subscribers: Xaosflux, Guarapiranga.

@Xaosflux suggested I should reignite this suggestion following my question at enwiki's Village Pump:

I see this has been asked several times in the past, but I was wondering whether there's been any progress toward implementing configurable initial table sorts. In the past, one frequent answer to this question has been: ''just save it sorted already''. That obviously doesn't resolve the issue for tables dynamically updated through formulas (e.g. [[List of countries and dependencies by population|population clocks]]) or transclusion from other pages. At the end, what this rigidity ends up promoting are frivolous edits to keep rank tables in the right order. Ideally, one should simply be able to specify in the data-sort-type tag, in addition to the data type, also whether the first sort should be ascending or descending, and whether the table should be pre-sorted by the ascribed column as soon as loaded onto the screen, e.g.:
! data-sort-type="alpha; first: ascending; initial: 3;" | Countries
! data-sort-type="number; first: descending; initial: 1;" | Population
! data-sort-type="date; first: ascending; initial: 2;" | Date

Xaosflux changed the subtype of this task from "Task" to "Feature Request".Dec 8 2019, 2:40 PM

Agree - this is really a feature request more than a bug, but it has been wanted for a long time.

Doing this in Javascript introduces accessibility concerns (someone with a reader isn't going to see the same table); doing this in PHP causes the same kinds of issue as auto-dates did.

I think this is a flat reject.

@Izno can you expand on why doing this server-side is a problem?

Aklapper lowered the priority of this task from Medium to Lowest.Dec 8 2019, 5:13 PM
Aklapper subscribed.

@Xaosflux it's a problem because it has to be implemented in the parser and it requires a two pass to do so. So first the entire wikicode needs to be parsed and converted into html (which is currently a string concatenation effort mostly) and then the whole thing needs to be losslessly (so with whitespace and comment preservation) loaded into a DOM tree, manipulated an serialised back to HTML text. While Parsoid in theory can do that latter step, Parsoid is not yet part of our core and I have no idea about the performance of such a setup, but I doubt it will be trivial. Lastly, someone has to reimplement 1300 lines of table sorting code from JS to PHP of course.

Thanks @TheDJ so it sounds like at the least this is blocked pending other future development - but not necessarily reason to never do it.

Ignoring earlier comment, maybe a way to get this implemented would be for the edit toolbars or a piece of user Javascript to provide a "reverse sort button" which does the heavy lifting of actually reverse sorting the table in the wikitext on the particular column.

That avoids the issues that I can see. It's a little bigger task though.

I don't know if still relevant/known, but the desired permalink seems to already work now (e.g. sorting the 3rd column descending):

https://translatewiki.net/w/i.php?title=Special%3ALanguageStats&x=D&code=qqq#sortable:3=desc

What I think is not there, is the ability to specify this preference from wikitext/HTML (e.g. to sort 3rd column descending as default).

That is not a good example for this task because that page has code dedicated to setting and handling the anchor.