src/main/webapp/jquery/js/dataTables.dateFormat.js
changeset 77 8f0eddd7aa85
child 105 66aeb6b3a3a7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/webapp/jquery/js/dataTables.dateFormat.js	Tue Apr 24 16:42:34 2012 +0200
@@ -0,0 +1,74 @@
+/**
+ * https://github.com/sedovsek/DataTables-EU-date-Plug-In
+ * commit 4069413
+ *
+ * Copyright 2011 https://github.com/sedovsek
+ *
+ * DataTables-EU-date-Plug-In is a plug-in for sorting EU Date (european date
+ * format), (d)d.mm(.yyyy) or (d)d/mm(/yyyy)
+ * 
+ * Example:
+ * <script type="text/javascript" src="jquery.dataTables.js"></script>
+ * <script type="text/javascript" src="dataTables.dateFormat.js"></script>
+ * <script type="text/javascript">
+ * 	$(document).ready(function() {
+ * 		$('#example').dataTable( {
+ * 			"aoColumns": [
+ * 				null,
+ * 				null,
+ * 				null,
+ * 				{ "sType": "eu_date" },
+ * 				null
+ * 			]
+ * 		} );
+ * 	} );
+ * </script>
+ * 
+ */
+
+function calculate_date(date) {
+	var date = date.replace(" ", "");
+	
+	if (date.indexOf('.') > 0) {
+		/*date a, format dd.mn.(yyyy) ; (year is optional)*/
+		var eu_date = date.split('.');
+	} else {
+		/*date a, format dd/mn/(yyyy) ; (year is optional)*/
+		var eu_date = date.split('/');
+	}
+	
+	/*year (optional)*/
+	if (eu_date[2]) {
+		var year = eu_date[2];
+	} else {
+		var year = 0;
+	}
+	
+	/*month*/
+	var month = eu_date[1];
+	if (month.length == 1) {
+		month = 0+month;
+	}
+	
+	/*day*/
+	var day = eu_date[0];
+	if (day.length == 1) {
+		day = 0+day;
+	}
+	
+	return (year + month + day) * 1;
+}
+
+jQuery.fn.dataTableExt.oSort['eu_date-asc'] = function(a, b) {
+	x = calculate_date(a);
+	y = calculate_date(b);
+	
+	return ((x < y) ? -1 : ((x > y) ?  1 : 0));
+};
+
+jQuery.fn.dataTableExt.oSort['eu_date-desc'] = function(a, b) {
+	x = calculate_date(a);
+	y = calculate_date(b);
+	
+	return ((x < y) ? 1 : ((x > y) ?  -1 : 0));
+};