tablesort icon indicating copy to clipboard operation
tablesort copied to clipboard

Dates not sorting properly

Open skykep opened this issue 3 years ago • 5 comments

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

skykep avatar Oct 28 '20 15:10 skykep

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.

skykep avatar Oct 28 '20 16:10 skykep

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

@skykep any chance you have a copy/paste solution 😛

mfridman avatar Nov 13 '20 03:11 mfridman

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.

skykep avatar Nov 13 '20 10:11 skykep

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

But as you mentioned, can be solved by tweaking the underlying parser.

mfridman avatar Nov 13 '20 16:11 mfridman

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>

skworden avatar May 05 '21 01:05 skworden