Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
8 lars 1
/**
2
 * This plug-in for DataTables represents the ultimate option in extensibility
3
 * for sorting date / time strings correctly. It uses
4
 * [Moment.js](http://momentjs.com) to create automatic type detection and
5
 * sorting plug-ins for DataTables based on a given format. This way, DataTables
6
 * will automatically detect your temporal information and sort it correctly.
7
 *
8
 * For usage instructions, please see the DataTables blog
9
 * post that [introduces it](//datatables.net/blog/2014-12-18).
10
 *
11
 * @name Ultimate Date / Time sorting
12
 * @summary Sort date and time in any format using Moment.js
13
 * @author [Allan Jardine](//datatables.net)
14
 * @depends DataTables 1.10+, Moment.js 1.7+
15
 *
16
 * @example
17
 *    $.fn.dataTable.moment( 'HH:mm MMM D, YY' );
18
 *    $.fn.dataTable.moment( 'dddd, MMMM Do, YYYY' );
19
 *
20
 *    $('#example').DataTable();
21
 */
22
 
23
(function($) {
24
 
25
$.fn.dataTable.moment = function ( format, locale ) {
26
	var types = $.fn.dataTable.ext.type;
27
 
28
	// Add type detection
29
	types.detect.unshift( function ( d ) {
30
		// Null and empty values are acceptable
31
		if ( d === '' || d === null ) {
32
			return 'moment-'+format;
33
		}
34
 
35
		return moment( d.replace ? d.replace(/<.*?>/g, '') : d, format, locale, true ).isValid() ?
36
			'moment-'+format :
37
			null;
38
	} );
39
 
40
	// Add sorting method - use an integer for the sorting
41
	types.order[ 'moment-'+format+'-pre' ] = function ( d ) {
42
		return d === '' || d === null ?
43
			-Infinity :
44
			parseInt( moment( d.replace ? d.replace(/<.*?>/g, '') : d, format, locale, true ).format( 'x' ), 10 );
45
	};
46
};
47
 
48
}(jQuery));