Re: [whatwg] Sortable Tables

Ian Hickson:
> On Thu, 1 Jul 2010, Christoph Päper wrote:

Darn, my reply from yesterday got lost in data nirvana. This is a slightly shorter version thereof.

>> So sortable tables should be marked as such.

Opt-in:

  <table sortable collapsible>

“sortable=auto” should be the default and resolve to ‘sortable’ if at least one column has a sort key assigned, and to ‘fixed’ (or the like) otherwise.

(Row and column collapsing is a related, but different beast. Let’s deal with that separately, later.)

>> Note that ‘col’ and ‘colgroup’ elements are hardly supported.

Nevertheless, it’s usually sufficient to mark one column as containing values to use as sort key. 

  <colgroup key=…>
  <col key=…>

Columns inherit the key from their group, but may override it.

>> non-sortable columns inside sortable tables should be marked as such.

  key=none

Not to be confused with fixed columns.

>> There are different ways to sort, eg. numeric, temporal or alphabetic 

  key=numeric 1 < 2 < 10
  key=alpha   Ä = ä = A&#x0308; (= a?), 1 < 10 < 2
  key=date    2012-11-08 = 2012-W45-4
  key=value   1000 g = 1 kg = 0.001 t > 1 lb

  key=style   although Excel can do this to some degree, it’s hardly useful
  key=class   slightly more useful
  key=id      ditto

>> and ascending or descending.

That’s better left to the UI: switch order when sorting for the second time.

>> Several columns may be used for sorting by some kind of priority.

Also primarily a UI question: use previously sorted column as secondary key.

  key=1       primary key for heuristic sorting algorithm

>> The original order must be restorable.

UI again, e.g. tristate column sort: ascending, descending, original, …

>> Cells should have an optional attribute indicating their sort key.

  <td value=0.454>1 lb

>> There may be columns that shall remain stable, eg. rank numbers.

  key=fixed

The sorting algorithm should not work on cells, but on slots (or slot values rather). 

Cells spanning multiple rows or columns may have to be split into one cell per slot and should be rejoined afterwards if possible. Note that ‘rowspan’ itself is safe for vertical sorting, unless it spans a ‘fixed’ column. Also, ‘colspan‘ is safe when it appears in the column to be sorted by.

  td {color: green}
  [rowspan] {color: red}

  <tr><td>1 <td rowspan=2>red                  1  red
  <tr><td>3                     =sort=col1=>   2  green
  <tr><td>2 <td>green                          3  red

The text reads its color! A cell at (1,1) – counting starts from 0 – never exists, the slot at the same position changes its value from ‘red’ to ‘green’.

Received on Thursday, 8 November 2012 16:22:50 UTC