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