Sorting dates in dd-MMM-yyyy format
Sorting dates in dd-MMM-yyyy format
Hi,
First of all, many thanks for the plug-in. I'm currently using freemarker to generate a table which is then displayed by Datatables. The freemarker returns a date of the form dd-MMM-yyyy and is recognized as a date. The sorting works fine in Chrome, which is where I designed the system, without an sType, but when I came to testing on IE and Firefox the sorting seems to have given in: without the sType, it sorts according to the day (e.g 1-Mar-2010, 2-Feb-2005, 3-Jan-2000) which is not very useful; and if I put the sType in it seems to give up on sorting at all.
Thoughts?
Hobnob
First of all, many thanks for the plug-in. I'm currently using freemarker to generate a table which is then displayed by Datatables. The freemarker returns a date of the form dd-MMM-yyyy and is recognized as a date. The sorting works fine in Chrome, which is where I designed the system, without an sType, but when I came to testing on IE and Firefox the sorting seems to have given in: without the sType, it sorts according to the day (e.g 1-Mar-2010, 2-Feb-2005, 3-Jan-2000) which is not very useful; and if I put the sType in it seems to give up on sorting at all.
Thoughts?
Hobnob
This discussion has been closed.
Replies
All I can imagine is that your particular date format 1-Mar-2010 is not an officially-supported format for a JavaScritp Date() object (which is used for sType: "date"). Chrome may be handling the date format anyhow, but the other browsers are failing out on it. Of course, without the sType it's sorted with normal alphanumerical sort, as you've seen.
If I'm right, you can probably modify DT core such that the value is intercepted before being passed into Date() and a custom function then performs a conversion (converting your format to one of the standards).
you can write your own custom sorting routine
client side: use http://www.datatables.net/release-datatables/examples/plug-ins/sorting_sType.html
serer side: alter the ORDER BY or even just change the format in SELECT queries
you can render the column in another format:
http://www.datatables.net/release-datatables/examples/advanced_init/column_render.html
I used the dd/mm/yyyy plug-in with an extra function converting the written month to a number e.g "Mar" -> "03"and it works like a charm.
Thanks for the help,
Hobnob