tablesort
tablesort copied to clipboard
Dates not sorting properly
Date sorting is not working as intended. Single-digit months are being weighed higher than double digit. For example, a descending order will go as follows: 6/1/2020 5/1/2020 4/1/2020 3/1/2020 11/1/2020 10/1/2020
If I format the date/time a little bit with moment, it'll sort properly (sort of). It sorts from left to run, so the year needs to be first, then month, then day...and so on. If using 12-hour mode with an am/pm appended at the end, it will actually put 8:26am later than 8:35pm.
Similar deal with the MM-DD-YYYY
format. I didn't bother playing around with the existing JS.
![Screen Shot 2020-11-12 at 10 56 53 PM](https://user-images.githubusercontent.com/6278244/99027256-c649fa80-253a-11eb-8fc7-7d0c2dc55d0f.png)
@skykep any chance you have a copy/paste solution 😛
Are you saying you prefer the dashes instead of slashes? I got around my problem by formatting it using moment. Try formatting your dates using moment().format('L'); If you need the dashes, that may not work.
Ahh, I thought it supported both dashes or slashes since the website example used both:
![Screen Shot 2020-11-13 at 11 14 12 AM](https://user-images.githubusercontent.com/6278244/99094094-5f136100-25a1-11eb-9372-8efeaebebb48.png)
But as you mentioned, can be solved by tweaking the underlying parser.
As a workaround - you can convert the date to seconds and then use that value in the data-sort
attribute. See docs.
<td data-sort='1620178326325'>05/04/2021</td>