W3C home > Mailing lists > Public > www-style@w3.org > December 2013

Re: [selectors] :sorted pseudoclass for sorted tables

From: Peter Linss <peter.linss@hp.com>
Date: Sat, 30 Nov 2013 21:33:09 -0800
Cc: "Tab Atkins Jr." <jackalmage@gmail.com>, www-style list <www-style@w3.org>
Message-Id: <06D9BFAB-7385-4572-ADA8-CB5C2F85797D@hp.com>
To: Brad Kemper <brad.kemper@gmail.com>

On Nov 26, 2013, at 8:00 AM, Brad Kemper <brad.kemper@gmail.com> wrote:

>> On Nov 25, 2013, at 8:06 PM, Peter Linss <peter.linss@hp.com> wrote:
>>> On Nov 25, 2013, at 1:05 PM, Tab Atkins Jr. <jackalmage@gmail.com> wrote:
>>> Now that HTML defines a way to sort tables, Hixie would like a
>>> pseudoclass letting authors target based on this:
>>> <https://www.w3.org/Bugs/Public/show_bug.cgi?id=20522>
>>> His proposal is for a :sorted pseudo-class, which also comes in a
>>> functional version, :sorted( [ ascending | descending ] ).  He's
>>> looking at defining it to match <th> elements that head a sorted
>>> column.
>>> Thoughts?  Any objections to me adding this to Selectors 4?
>> Sounds reasonable. If we¡¯re going to add it though, I suggest we also add the capability to select on the ordinality of the sort, something like:
>> :sorted( [ ascending | descending ] || <number> )
> Would numeric vs. alphabetic change how it was styled? I wouldn't think so. I imagine it would mainly be useful for setting a background color or maybe gradient for the column's TDs and TH's, and for setting a triangle or arrow background in the TH.

The number isn¡¯t for numeric vs alphabetic sorting, it¡¯s the ordinality of the sort key, as in, sort by this column first, then this second. When multiple sort keys are being used, it¡¯ll likely be useful to style them so that the ordinality is visible.

>> It¡¯s also unfortunate that the selector uses ¡®ascending¡¯ and ¡®descending¡¯ where HTML uses ¡®¡¯ and ¡®reversed¡¯ for the sort order. It would be easier for authors to remember if they were in sync.
> Then I think we should have :sorted( [ normal | reversed | unsorted ] ). 'Unsorted' would be for setting styles that only apply when the sister values do not apply. 'sorted(normal)' would go well with a '' sort order value.

The problem with ¡®normal¡¯ | ¡®reversed¡¯ keywords is that they lead to potential conflicts if the sorting algorithm is even extended. For instance, say they add the ability to sort case-sensitively, an ascending case-sensitive sort would still match :sorted(ascending) but it would stop matching :sorted(normal).

> Is there a link to where this is described in HTML?

It¡¯s in the WHATWG draft at the moment, I¡¯m sure it¡¯ll get propagated to the W3C version at some point.

> Does the TH get an attribute of 'sorted' and 'sorted=reversed' or something?

There is a ¡®sorted¡¯ attribute which contains the direction and ordinality, note that both are optional so styling sorting with attribute selectors gets unnecessarily complicated, e.g.:
th[sorted]:not([sorted~=¡°reversed¡± i])

> Do the TDs in scope also get to use the pseudo-class?

No, and not needed with the column combinator, you can select the TDs in the sorted column via:
:sorted || td

> It seems like the attribute should also be able to be used on a COL or TR, but I guess that is not up to us.

Received on Sunday, 1 December 2013 05:33:36 UTC

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:08:37 UTC