Page MenuHomePhabricator

Date returned by query gets treated like string with respect to sorting in table
Closed, ResolvedPublic


Author: trueskew

I've got pages that each have multiple SIO records, and each record includes a date (Status Report Date of type Date). I was able to create a 2 column summary table that lists each page along with the date of the newest record with this query:
{{#ask:[[Category:Status Report]] [[Has Contributor::{{PAGENAME}}]]

?Has Effort=Effort
sort=Has Effort
intro={{display2ColSortTableHeadercol1=Effortcol2=Last Update}}


where Template:display2ColTableViewStatusReportEntry holds

[[{{{1}}}#{{#ask: [[Status Report Record::{{{1}}}]]?Has Status Report Date=sort=Has Status Report Dateformat=listlimit=1order=descendingmainlabel=-link=noneheaders=hidesearchlabel= }}{{{2}}} - View]]
{{#ask: [[Status Report Record::{{{1}}}]]?Has Status Report Date=sort=Has Status Report Dateformat=listlimit=1order=descendingmainlabel=-link=noneheaders=hidesearchlabel= }}


This results in a column sort table like

Effort             v Last Update

Soda Project - View 4 November 2010
Burger Project - View 25 October 2010
Hot Dog Project - View 20 May 2010
Sandwich Project - View 19 October 2010
The table shown above replicates one sorted by Last Update in descending order. It sorts alphanumerically rather than by date.

Version: unspecified
Severity: normal



Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:22 PM
bzimport set Reference to bz25768.

dan.bolser wrote:

*** This bug has been marked as a duplicate of bug 25807 ***

  • Bug 25807 has been marked as a duplicate of this bug. ***

First, this bug is not "critical". Mainly, the issue is a basic limitation of the "recipe" at [1] and this recipe should warn about this. SMW takes special precautions to avoid this problem in its own tables. By using a manually created table, this special handling is eliminated.

The sortable table code of MediaWiki cannot handle dates. To make them sort properly, one needs to provide numeric sortkeys using the "data-sort-value" attribute in td elements (look at the HTML of any real SMW table for examples). When manually creating tables, one is in charge of providing this information, or one needs to use JavaScript that can handle dates natively (which is difficult due to the complex format). To allow this to be done manually, I have now (in r111269) added a new output format "sortkey" to Type:Date by which one can obtain a numeric sortkey as needed for "data-sort-value". For example, the following query displays dates and their sortkeys:

{{#ask: [[Modification date::+]]

?Modification date
?Modification date#sortkey


For properties that can have many values, only one sortkey must be used (since the whole table row is sorted as one, even if many dates are in one cell). This can be achieved by using +limit like so:

{{#ask: [[testdate::+]]



It would be nice if the recipe could be extended by all this information, and ideally with a recipe for building the correct HTML code. This goes as far as SMW can assist the manual creation of sortable tables, so I am closing this bug.


dan.bolser wrote:

The best would be to make the recipe obsolete by implementing some better 'format results' syntax, but I see that this is not easy.

In the meantime, I'll just put a pointer there to here.