Closed brendanheyu closed 7 years ago
I have the same problem
It’s unlikely we’ll support this level of sorting in the plugin. We expose functionality to do this through custom sort functions. See “Advanced Option: Custom Sort Functions” on https://github.com/filamentgroup/tablesaw#sortable
An easy way to work around date sorting specifically, is to precede the formatted date with a machine-sortable version, and then use CSS to hide the machine-sortable version. ISO format works nicely.
Note, however, that display:none probably won't work. It has to be technically visible, but can be hidden from the user.
For example,
<table class="tablesaw tablesaw-stack" data-tablesaw-mode="stack" data-tablesaw-sortable>
<thead>
<tr>
<th data-tablesaw-sortable-col>Date</th>
<th data-tablesaw-sortable-col>Something else</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<span style="position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden;">
2017-09-01T10:51:24
</span>
Sep 1
</td>
<td>5</td>
</tr>
<tr>
<td>
<span style="position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden;">
2017-08-31T10:51:24
</span>
Aug 31
</td>
<td>10</td>
</tr>
</tbody>
</table>
Thanks @josephsong for the work-around- I'm finding myself in a similar position needing to essentially abstract the sort date value from the display value. @zachleat How difficult would it be to modify the script to look at a data attribute on the <td>
such as data-sort-value
instead of the cell value itself?
I'm not able to sort columns with dates as it seems there is no way to define the date format in use.
Maybe it could be done as :
data-tablesaw-sortable-date="true" data-tablesaw-sortable-date-format="dd/mm/yyyy"
That would be really helpful.