Date Sorting Problem
Date Sorting Problem

Hello!
I am having an issue with how my table is sorting the date column. It doesn't appear to ascend or descend the data chronologically:
6/8/2019
6/6/2019
6/10/2019
6/9/2019
6/10/2019
From what I have gathered from the forums it seems as though the columns data is being treated as strings which is what is throwing off the sort. I thought that I could just get away with adding this bit code to my script, but it doesn't appear to be working:
"columnDefs": [{"type": "date", "targets": 0}]
That isn't fixing the problem, however. What am I missing? Any help would be greatly appreciated!
This question has an accepted answers - jump to answer
Answers
There are many posts in here about date sorting. For example:
https://datatables.net/forums/discussion/53126
Yeah, I've been scouring through posts and I've tried a few of the options.
I've added:
Along with the CDN's to my code. That didn't appear to do the trick either. Seems like most of what I find are users wanting to change the appearance of the date display (such as to dd/mm/yy).
You need to make sure the format you specify matches the format you have using this:
http://momentjs.com/docs/#/displaying/
The dates you listed as your data does not match the format you are specifying. It should look more like this:
$.fn.dataTable.moment( 'M/D/YYYY' );
Kevin
Thanks for the response! I was neglecting to change the format. After editing my code, however, I am still not getting the result that I want. I've got both CDN's added to my code along with the new code that you provided to my script and I am not having any luck. Should just be as follows, correct?
DataTable Script:
Page code:
Without seeing an example test case with your data its hard to say. Your data example works here:
http://live.datatables.net/wevugexo/1/edit
If you have something other than dates that match the format specified then the plugin won't work. Do you have other data in that column?
If you continue to have difficulties please post a link to your page or a test case replicating the issue or update my test case.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
I'll have to look a bit more into then. There isn't any other data in the column, but I don't have the site live yet to show an example. If I can get it launched then maybe I will circle back here.
Thanks for the responses!