Sort by both Month/Year and just Year
Sort by both Month/Year and just Year
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,
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,
This discussion has been closed.
Replies
> 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