Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
8 lars 1
/**
2
 * Sorts a column containing IP addresses in typical dot notation. This can
3
 * be most useful when using DataTables for a networking application, and
4
 * reporting information containing IP address. Also has a matching type
5
 * detection plug-in for automatic type detection.
6
 *
7
 *  @name IP addresses
8
 *  @summary Sort IP addresses numerically
9
 *  @author Brad Wasson
10
 *
11
 *  @example
12
 *    $('#example').dataTable( {
13
 *       columnDefs: [
14
 *         { type: 'ip-address', targets: 0 }
15
 *       ]
16
 *    } );
17
 */
18
 
19
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
20
	"ip-address-pre": function ( a ) {
21
		var m = a.split("."), x = "";
22
 
23
		for(var i = 0; i < m.length; i++) {
24
			var item = m[i];
25
			if(item.length == 1) {
26
				x += "00" + item;
27
			} else if(item.length == 2) {
28
				x += "0" + item;
29
			} else {
30
				x += item;
31
			}
32
		}
33
 
34
		return x;
35
	},
36
 
37
	"ip-address-asc": function ( a, b ) {
38
		return ((a < b) ? -1 : ((a > b) ? 1 : 0));
39
	},
40
 
41
	"ip-address-desc": function ( a, b ) {
42
		return ((a < b) ? 1 : ((a > b) ? -1 : 0));
43
	}
44
} );