≡
×
Plus
Manual
Examples
Reference
Download
Blog
Community
Support
Sorting dates with only month and year
Sorting dates with only month and year
romsok
Posts: 38
Questions: 0
Answers: 0
January 2010
edited January 2010
in
General
Hi,
I am populating a column with only month and a year because my table displays monthly stats.
What format should the date (month and year) be in if I want the table to sort it correctly?
Replies
allan
Posts: 65,813
Questions: 1
Answers: 10,949
Site admin
January 2010
You'll need to use a custom sorting plug-in, because I don't believe that any browser's Date.parse() will parse just hte month and year. It should be easy to modify one of the ones available form here: http://datatables.net/plug-ins/sorting
Regards,
Allan
romsok
Posts: 38
Questions: 0
Answers: 0
February 2010
Thanks,
I used the examples to implement this comparison function.
Could someone please criticize my code and let me know how it could have been better written?
[code]
jQuery.fn.dataTableExt.oSort['month-year-desc'] = function(x,y)
{
//array of months
var months=["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
dateComponents = x.split(",");//parse x on comma
dateComponents[1] = jQuery.trim(dateComponents[1]);
//determine year
var year = dateComponents[1];
//determine month
var month = 0;
for(i=0; i
This discussion has been closed.
Replies
Regards,
Allan
I used the examples to implement this comparison function.
Could someone please criticize my code and let me know how it could have been better written?
[code]
jQuery.fn.dataTableExt.oSort['month-year-desc'] = function(x,y)
{
//array of months
var months=["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
dateComponents = x.split(",");//parse x on comma
dateComponents[1] = jQuery.trim(dateComponents[1]);
//determine year
var year = dateComponents[1];
//determine month
var month = 0;
for(i=0; i