|
77
|
1 |
/**
|
|
|
2 |
* https://github.com/sedovsek/DataTables-EU-date-Plug-In
|
|
|
3 |
* commit 4069413
|
|
|
4 |
*
|
|
|
5 |
* Copyright 2011 https://github.com/sedovsek
|
|
|
6 |
*
|
|
|
7 |
* DataTables-EU-date-Plug-In is a plug-in for sorting EU Date (european date
|
|
|
8 |
* format), (d)d.mm(.yyyy) or (d)d/mm(/yyyy)
|
|
|
9 |
*
|
|
|
10 |
* Example:
|
|
|
11 |
* <script type="text/javascript" src="jquery.dataTables.js"></script>
|
|
|
12 |
* <script type="text/javascript" src="dataTables.dateFormat.js"></script>
|
|
|
13 |
* <script type="text/javascript">
|
|
|
14 |
* $(document).ready(function() {
|
|
|
15 |
* $('#example').dataTable( {
|
|
|
16 |
* "aoColumns": [
|
|
|
17 |
* null,
|
|
|
18 |
* null,
|
|
|
19 |
* null,
|
|
|
20 |
* { "sType": "eu_date" },
|
|
|
21 |
* null
|
|
|
22 |
* ]
|
|
|
23 |
* } );
|
|
|
24 |
* } );
|
|
|
25 |
* </script>
|
|
|
26 |
*
|
|
|
27 |
*/
|
|
|
28 |
|
|
|
29 |
function calculate_date(date) {
|
|
|
30 |
var date = date.replace(" ", "");
|
|
|
31 |
|
|
|
32 |
if (date.indexOf('.') > 0) {
|
|
|
33 |
/*date a, format dd.mn.(yyyy) ; (year is optional)*/
|
|
|
34 |
var eu_date = date.split('.');
|
|
|
35 |
} else {
|
|
|
36 |
/*date a, format dd/mn/(yyyy) ; (year is optional)*/
|
|
|
37 |
var eu_date = date.split('/');
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
/*year (optional)*/
|
|
|
41 |
if (eu_date[2]) {
|
|
|
42 |
var year = eu_date[2];
|
|
|
43 |
} else {
|
|
|
44 |
var year = 0;
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
/*month*/
|
|
|
48 |
var month = eu_date[1];
|
|
|
49 |
if (month.length == 1) {
|
|
|
50 |
month = 0+month;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
/*day*/
|
|
|
54 |
var day = eu_date[0];
|
|
|
55 |
if (day.length == 1) {
|
|
|
56 |
day = 0+day;
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
return (year + month + day) * 1;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
jQuery.fn.dataTableExt.oSort['eu_date-asc'] = function(a, b) {
|
|
|
63 |
x = calculate_date(a);
|
|
|
64 |
y = calculate_date(b);
|
|
|
65 |
|
|
|
66 |
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
|
|
|
67 |
};
|
|
|
68 |
|
|
|
69 |
jQuery.fn.dataTableExt.oSort['eu_date-desc'] = function(a, b) {
|
|
|
70 |
x = calculate_date(a);
|
|
|
71 |
y = calculate_date(b);
|
|
|
72 |
|
|
|
73 |
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
|
|
|
74 |
};
|