Last modified: 2013-07-20 20:50:50 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T17406, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 15406 - Sortable tables: Force sortorder of a column
Sortable tables: Force sortorder of a column
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
JavaScript (Other open bugs)
unspecified
All All
: Normal enhancement with 3 votes (vote)
: ---
Assigned To: Nobody - You can work on this!
: need-unittest, patch-need-review
: 13535 (view as bug list)
Depends on:
Blocks: 31601
  Show dependency treegraph
 
Reported: 2008-09-01 02:58 UTC by SharkD
Modified: 2013-07-20 20:50 UTC (History)
7 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
unified diff file (1.98 KB, patch)
2008-09-01 02:58 UTC, SharkD
Details
unified diff file (2.31 KB, patch)
2008-09-02 22:45 UTC, SharkD
Details
unified diff file (2.30 KB, patch)
2008-09-02 23:34 UTC, SharkD
Details

Description SharkD 2008-09-01 02:58:34 UTC
Created attachment 5244 [details]
unified diff file

This patch adds the ability to force a particular sortorder of a column instead of relying on the script to detect the proper sortorder. This is achieved by adding a "sortorder" attribute to the column header, and specifying the desired sortorder as the value of this attribute. The actual options, however, need to be updated to be current with the other patches. The ones included in the diff can be considered examples used more for demonstration purposes.
Comment 1 Daniel Friesen 2008-09-01 08:28:47 UTC
sortorder is not a valid XHTML attribute. Adding this patch will go against our attempts at keeping MediaWiki XHTML valid.

I recommend finding a way to do this using classes rather than invalid XHTML attributes.
Comment 2 SharkD 2008-09-01 14:41:15 UTC
(In reply to comment #1)
> sortorder is not a valid XHTML attribute. Adding this patch will go against our
> attempts at keeping MediaWiki XHTML valid.
> I recommend finding a way to do this using classes rather than invalid XHTML
> attributes.

The proposal could certainly be changed to use classes. However, the code already uses a non standard XHTML attribute, "sortdir". Should this be changed as well?
Comment 3 Daniel Friesen 2008-09-01 14:54:16 UTC
Sortdir is an attribute set internally by the js when you click on the sort button. It's ok for JS to set non-standard attributes.

There is another proposal for a default reverse sort, that patch should probably make sure to be one that sets that attribute.
Comment 4 SharkD 2008-09-01 15:58:54 UTC
It's silly to say that non-standard attributes are supported when added by JavaScript, but not otherwise. You're confusing being able to pass a verification test with the issue behind the proviso.
Comment 5 Aryeh Gregor (not reading bugmail, please e-mail directly) 2008-09-01 19:58:34 UTC
The sortdir thing should be changed too.  Frankly I don't see why authors shouldn't be allowed to make up their own site-specific attributes.  It's handy sometimes.  But we want the trendy Standards-Compliant label, I suppose, so we have to live with it.

There's no way, in any event, for users to add a custom attribute in wikitext.  Something like this:

{| class="sortable"
|-
! sortorder="numeric" | This is the header
...
|}

will just have the "sortorder" attribute stripped as invalid.  So I'm not clear on how this is supposed to be used, even if we did want to break XHTML validity, which we don't.
Comment 6 Daniel Friesen 2008-09-01 20:04:58 UTC
It's only used internally. Attributes in the code are commonly used for storing variables related to a node. In this case we store the current sort direction so that we can reverse it on the next sort.

I can't remember if we have a class to make the list initially sorted... If we don't it would be good. Either way a reversesort css class to make this sort in the opposite direction by default would be nice.
Comment 7 SharkD 2008-09-02 01:05:11 UTC
I took a look at the code to see how easy it would be to accomplish this using only class names. While it could be done, it would require supporting a separate classname for each sorting function. As the number of sorting functions increases, so does the number of classes you have to check for (as opposed to checking for a single, uniquely named attribute). I'm worried that the large number of classes will negatively affect the speed of the script.
Comment 8 Daniel Friesen 2008-09-02 10:28:32 UTC
You don't have to check for a pile of stuff, just a pattern.

var sortorder
Comment 9 Daniel Friesen 2008-09-02 10:47:44 UTC
Ack, wtf, I write a section of JS code, and bugzilla deletes it. Bah...

Well, really you'd just break up the className by \s  and then test for any classNames that start with something like sortorder-
Comment 10 SharkD 2008-09-02 17:59:50 UTC
You mean, like:

"sortorder-numeric"
"sortorder-alphanumeric"
"sortorder-date1"
...

I suppose that would work.
Comment 11 SharkD 2008-09-02 22:45:18 UTC
Created attachment 5263 [details]
unified diff file

I created an alternate version that uses class names instead of attributes. Seems to work OK.
Comment 12 SharkD 2008-09-02 23:18:35 UTC
Actually, "sortorder-XXXX" could be truncated to "sort-XXXX" without any problems.
Comment 13 SharkD 2008-09-02 23:34:38 UTC
Created attachment 5266 [details]
unified diff file

"sortorder-xxxx" classes renamed to "sort-xxxx".
Comment 14 Steve Sanbeg 2009-01-21 19:21:52 UTC
Should the regex be anchored?  I think something like
 var sortClass = ('' + td.className + '').match(/^sort-\w+$/);

would be more appropriate
Comment 15 Steve Sanbeg 2009-01-21 19:23:03 UTC
(In reply to comment #14)
> Should the regex be anchored?  I think something like
>  var sortClass = ('' + td.className + '').match(/^sort-\w+$/);
> 
> would be more appropriate
> 

Oops, that would probably break multiple classes....
Comment 16 SharkD 2009-01-22 10:43:41 UTC
(In reply to comment #15)
> (In reply to comment #14)
> > Should the regex be anchored?  I think something like
> >  var sortClass = ('' + td.className + '').match(/^sort-\w+$/);
> > 
> > would be more appropriate
> > 
> Oops, that would probably break multiple classes....

You just made me notice that the quotes are supposed to have spaces in them. I.e.

-	var sortClass = ('' + td.className + '').match(/(sort\-\w+)/);
+	var sortClass = (' ' + td.className + ' ').match(/(sort\-\w+)/);

-Mike
Comment 17 Steve Sanbeg 2009-01-23 20:52:13 UTC
(In reply to comment #16)
> (In reply to comment #15)
> > (In reply to comment #14)
> > > Should the regex be anchored?  I think something like
> > >  var sortClass = ('' + td.className + '').match(/^sort-\w+$/);
> > > 
> > > would be more appropriate
> > > 
> > Oops, that would probably break multiple classes....
> 
> You just made me notice that the quotes are supposed to have spaces in them.
> I.e.
> 
> -       var sortClass = ('' + td.className + '').match(/(sort\-\w+)/);
> +       var sortClass = (' ' + td.className + ' ').match(/(sort\-\w+)/);
> 
> -Mike
> 

Then should the regex have the spaces, too? i.e.
  var sortClass = (' ' + td.className + ' ').match(/ (sort\-\w+) /);

It seems like that should avoid false positives in the match.
Comment 18 dpotter 2009-01-24 15:43:21 UTC
*** Bug 13535 has been marked as a duplicate of this bug. ***
Comment 19 SharkD 2009-01-26 21:18:09 UTC
(In reply to comment #17)
> Then should the regex have the spaces, too? i.e.
>   var sortClass = (' ' + td.className + ' ').match(/ (sort\-\w+) /);
> It seems like that should avoid false positives in the match.

I suppose it can't hurt. I don't think false positives are very likely though.

-Mike
Comment 20 bluehairedlawyer 2009-12-23 20:22:33 UTC
How come this has stalled for so long?
Comment 21 DieBuche 2010-12-20 00:08:42 UTC
will be fixed in the jQuery implementation
Comment 22 DieBuche 2011-01-08 15:18:27 UTC
fixed in patch for Bug 8028
Comment 23 SharkD 2011-01-12 19:36:29 UTC
Quote: "How come this has stalled for so long?"

Because I got into an argument with the devs and they said they would no longer be looking at my requests.
Comment 24 DieBuche 2011-04-15 08:36:31 UTC
r86088
Comment 25 Brion Vibber 2011-06-22 20:02:19 UTC
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.)
Comment 26 DieBuche 2011-07-07 08:25:04 UTC
reclosing
Comment 27 Timeshifter 2011-11-27 01:41:39 UTC
This needs to be implemented soon. It is very difficult to follow all the rules in this and other sections of the Help:Sorting page. Even experienced table editors like myself have difficulty. There are so many rules, and they change at times:
*http://en.wikipedia.org/wiki/Help:Sorting#Numerical_sorting_problems

I have been updating Help:Sorting, and doing various tests. There are still some inexplicable bugs where a column follows all the rules for numerical sorting, and it still does not sort correctly.  I have looked at r86088 comments, and I am glad there has been some serious work down. 

Has work on this stalled? If you are working on this then please also incorporate my request to put the sorting icon above the text. This is very important. See my comment #15 here:
*https://bugzilla.wikimedia.org/show_bug.cgi?id=31755#c15
Comment 28 Timeshifter 2012-09-26 18:50:16 UTC
See this related feature request: 
Bug 24523 - "Make table sorting ignore refs when determining data type".
Comment 29 Timeshifter 2012-09-30 07:59:15 UTC
This has been fixed in English Wikipedia according to discussion here:
*[[Help_talk:Sorting#HTML5]]
*[[Help_talk:Sorting#Documentation]]

data-sort-type plus a value forces a column to be sorted according to a specific method. 

See also:
*[[Help:Sorting#Numerical_sorting_problems]] 
*[[meta:Help:Sorting#Sort_modes]] - go to the subsection about forcing the sort mode for a column. It lists the values that can be used.
Comment 30 Derk-Jan Hartman 2013-07-20 20:49:59 UTC
I think we can call this one closed now.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links