Sorting Unusual Date Format?
Sorting Unusual Date Format?
Hi all,
I'm new to Datatables - I've been using the Charisma framework and it comes with them, so I've been muddling along as I go trying to get used to the features.
I had my dates formatted like this:
2015-07-26
And sorting by date worked fine. A user asked for the date format to be changed to this:
Sun 26th July 2015
And sorting, naturally, no longer works as users would expect it to.
Is there an easy way to fix the sorting? I'm guessing the route would be to have a hidden column with the date in the standard format, and bind the sorting to that when the user clicks on the date column? I'm not sure where to start with that, though, or even if I'm just making things too complicated.
Thanks.
Answers
One way could be to use datatables html5-data-attributes , inspect the html code of that table and notice the
data-order
attributeThanks daniel_r!
I've tried that, and it doesn't appear to be having any effect (The table is generated from a MySQL query if that makes any difference). I was running 1.0.8 and I've updated to 1.10, but no joy.
This is how the table is generated (inside a loop):
Thanks again.
I use hidden column for sorting in cases like this. I posted an example a while ago:
https://datatables.net/forums/discussion/25782/how-to-sort-using-a-hidden-column-in-1-10-0
not a php user but make sure you place miliseconds of your date in
data-order
just like in the exampleAnother option is to use the date / time sorting plug-in from this blog post. It will work with virtually any format.
Allan