Making data tables dynamically sortable without JavaScript would be a big timesaver for devs and make the implementations consistent across the web for users. Since it’s possible to only want some columns or rows sortable, I propose adding sort
as an attribute to th
elements.
<table>
<caption>
Color names and values
</caption>
<tbody>
<tr>
<th sort scope="col">Name</th>
<th sort scope="col">HEX</th>
<th sort scope="col">HSLa</th>
<th sort scope="col">RGBa</th>
</tr>
<tr>
<th sort scope="row">Teal</th>
<td><code>#51F6F6</code></td>
<td><code>hsla(180, 90%, 64%, 1)</code></td>
<td><code>rgba(81, 246, 246, 1)</code></td>
</tr>
<tr>
<th sort scope="row">Goldenrod</th>
<td><code>#F6BC57</code></td>
<td><code>hsla(38, 90%, 65%, 1)</code></td>
<td><code>rgba(246, 188, 87, 1)</code></td>
</tr>
</tbody>
</table>
To handle sorting different values, sort
should accept values that are valid arguments for Intl.Collator
.
For accessibility, there should be some standard way of announcing the th
elements as “sortable” and stating the sort order if engaged (“ascending”, “descending”) and responding to some keypresses to activate/toggle the sorting.