Sorting dates with only month and year

Sorting dates with only month and year

romsokromsok Posts: 38Questions: 0Answers: 0
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

  • allanallan Posts: 63,489Questions: 1Answers: 10,469 Site admin
    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
  • romsokromsok Posts: 38Questions: 0Answers: 0
    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.