| 8 |
lars |
1 |
/**
|
|
|
2 |
* This sorting plug-in will sort, in calendar order, data which
|
|
|
3 |
* is in the format "MMM yyyy" or "MMMM yyyy". Inspired by forum discussion:
|
|
|
4 |
* http://datatables.net/forums/discussion/1242/sorting-dates-with-only-month-and-year
|
|
|
5 |
*
|
|
|
6 |
* Please note that this plug-in is **deprecated*. The
|
|
|
7 |
* [datetime](//datatables.net/blog/2014-12-18) plug-in provides enhanced
|
|
|
8 |
* functionality and flexibility.
|
|
|
9 |
*
|
|
|
10 |
* @name Date (MMM yyyy) or (MMMM yyyy)
|
|
|
11 |
* @anchor Sort dates in the format `MMM yyyy` or `MMMM yyyy`
|
|
|
12 |
* @author Phil Hurwitz
|
|
|
13 |
* @deprecated
|
|
|
14 |
*
|
|
|
15 |
* @example
|
|
|
16 |
* $('#example').DataTable( {
|
|
|
17 |
* columnDefs: [
|
|
|
18 |
* { type: 'stringMonthYear', targets: 0 }
|
|
|
19 |
* ]
|
|
|
20 |
* } );
|
|
|
21 |
*/
|
|
|
22 |
|
|
|
23 |
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
|
|
|
24 |
"stringMonthYear-pre": function (s) {
|
|
|
25 |
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
|
26 |
|
|
|
27 |
var dateComponents = s.split(" ");
|
|
|
28 |
dateComponents[0] = dateComponents[0].replace(",", "");
|
|
|
29 |
dateComponents[1] = jQuery.trim(dateComponents[1]);
|
|
|
30 |
|
|
|
31 |
var year = dateComponents[1];
|
|
|
32 |
|
|
|
33 |
var month = 0;
|
|
|
34 |
for (var i = 0; i < months.length; i++) {
|
|
|
35 |
if (months[i].toLowerCase() == dateComponents[0].toLowerCase().substring(0,3)) {
|
|
|
36 |
month = i;
|
|
|
37 |
break;
|
|
|
38 |
}
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
return new Date(year, month, 1);
|
|
|
42 |
},
|
|
|
43 |
|
|
|
44 |
"stringMonthYear-asc": function (a, b) {
|
|
|
45 |
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
|
|
|
46 |
},
|
|
|
47 |
|
|
|
48 |
"stringMonthYear-desc": function (a, b) {
|
|
|
49 |
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
|
|
|
50 |
}
|
|
|
51 |
});
|