stationer / SortTable

A pure JavaScript (no dependencies) solution to make HTML Tables sortable
MIT License
37 stars 12 forks source link

Date sort #8

Closed teicors closed 1 year ago

teicors commented 4 years ago

Hi, I'm having an issue during the sort of a date or may be is better to say "which format of data should I use in order to keep the right ordering?". I'm using the italian format but I'm having this sort from the earliest date:

29/08/2020 28/09/2020 28/07/2020 27/09/2020

Is it possible to specify the format ?

Thanks, Angelo

tyleruebele commented 4 years ago

There is not currently a way to specify the format, but, there is an easy way to create a new sort time. See the existing date helper function at https://github.com/stationer/SortTable/blob/master/sort-table.js#L133 You can replace this in your own code, or add a new type by defining it like this:

sortTable.date_dmy = function(Cell) {
    // parse the date in dmy format and return a comparable value such as a unix timestamp
};

Should you happen to do this before me, a pull request is welcome.

tyleruebele commented 4 years ago

PS. By default I think it uses the local computer's locale settings, because it leans on JS built in date handling.

tyleruebele commented 4 years ago

A work around could be to include a sortable values, such as an ISO date, or a unix timestamp, in a hidden span at the start of the cell and use the raw type.