| 4 |
lars |
1 |
/*
|
|
|
2 |
* Adds a new sorting option to dataTables called `date-dd-mmm-yyyy`. Also
|
|
|
3 |
* includes a type detection plug-in. Matches and sorts date strings in
|
|
|
4 |
* the format: `dd/mmm/yyyy`. For example:
|
|
|
5 |
*
|
|
|
6 |
* * 02-FEB-1978
|
|
|
7 |
* * 17-MAY-2013
|
|
|
8 |
* * 31-JAN-2014
|
|
|
9 |
*
|
|
|
10 |
* Please note that this plug-in is **deprecated*. The
|
|
|
11 |
* [datetime](//datatables.net/blog/2014-12-18) plug-in provides enhanced
|
|
|
12 |
* functionality and flexibility.
|
|
|
13 |
*
|
|
|
14 |
* @name Date (dd-mmm-yyyy)
|
|
|
15 |
* @summary Sort dates in the format `dd-mmm-yyyy`
|
|
|
16 |
* @author [Jeromy French](http://www.appliedinter.net/jeromy_works/)
|
|
|
17 |
* @deprecated
|
|
|
18 |
*
|
|
|
19 |
* @example
|
|
|
20 |
* $('#example').dataTable( {
|
|
|
21 |
* columnDefs: [
|
|
|
22 |
* { type: 'date-dd-mmm-yyyy', targets: 0 }
|
|
|
23 |
* ]
|
|
|
24 |
* } );
|
|
|
25 |
*/
|
|
|
26 |
|
|
|
27 |
(function () {
|
|
|
28 |
|
|
|
29 |
var customDateDDMMMYYYYToOrd = function (date) {
|
|
|
30 |
"use strict"; //let's avoid tom-foolery in this function
|
|
|
31 |
// Convert to a number YYYYMMDD which we can use to order
|
|
|
32 |
var dateParts = date.split(/-/);
|
|
|
33 |
return (dateParts[2] * 10000) + ($.inArray(dateParts[1].toUpperCase(), ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"]) * 100) + (dateParts[0]*1);
|
|
|
34 |
};
|
|
|
35 |
|
|
|
36 |
// This will help DataTables magic detect the "dd-MMM-yyyy" format; Unshift
|
|
|
37 |
// so that it's the first data type (so it takes priority over existing)
|
|
|
38 |
jQuery.fn.dataTableExt.aTypes.unshift(
|
|
|
39 |
function (sData) {
|
|
|
40 |
"use strict"; //let's avoid tom-foolery in this function
|
|
|
41 |
if (/^([0-2]?\d|3[0-1])-(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)-\d{4}/i.test(sData)) {
|
|
|
42 |
return 'date-dd-mmm-yyyy';
|
|
|
43 |
}
|
|
|
44 |
return null;
|
|
|
45 |
}
|
|
|
46 |
);
|
|
|
47 |
|
|
|
48 |
// define the sorts
|
|
|
49 |
jQuery.fn.dataTableExt.oSort['date-dd-mmm-yyyy-asc'] = function (a, b) {
|
|
|
50 |
"use strict"; //let's avoid tom-foolery in this function
|
|
|
51 |
var ordA = customDateDDMMMYYYYToOrd(a),
|
|
|
52 |
ordB = customDateDDMMMYYYYToOrd(b);
|
|
|
53 |
return (ordA < ordB) ? -1 : ((ordA > ordB) ? 1 : 0);
|
|
|
54 |
};
|
|
|
55 |
|
|
|
56 |
jQuery.fn.dataTableExt.oSort['date-dd-mmm-yyyy-desc'] = function (a, b) {
|
|
|
57 |
"use strict"; //let's avoid tom-foolery in this function
|
|
|
58 |
var ordA = customDateDDMMMYYYYToOrd(a),
|
|
|
59 |
ordB = customDateDDMMMYYYYToOrd(b);
|
|
|
60 |
return (ordA < ordB) ? 1 : ((ordA > ordB) ? -1 : 0);
|
|
|
61 |
};
|
|
|
62 |
|
|
|
63 |
})();
|