Sort by both Month/Year and just Year

Sort by both Month/Year and just Year

KyndylanKyndylan Posts: 1Questions: 0Answers: 0
edited July 2012 in Plug-ins
The plugin "Month / Year" worked straight off the bat for me, which was great. It sorts both mm/yyyy and mmm/yyyy, which is fantastic. My problem is that I've got some entries in my table for which there is no month, just a year. These don't seem to be sorted. As I'm a complete novice, could anyone lend a helping hand? I expect it's a pretty simple change that's required.

Here's the code for the plugin as is:
[code]jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"monthYear-pre": function ( a ) {
return new Date('01 '+a);
},

"monthYear-asc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},

"monthYear-desc": function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );[/code]

On a very related note, how hard would it be to add functionality for seasons? As in "Summer 2012" - I guess make it analogous to June or something like that?

Many thanks,

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Perhaps you could just check to see if the string (in the 'pre' function) is only a year, and if so, prefix a month as well as a date, like the pre function is currently doing.

    > On a very related note, how hard would it be to add functionality for seasons? As in "Summer 2012" - I guess make it analogous to June or something like that?

    Yes - I think that's probably a good approach.

    Allan
This discussion has been closed.