| 8 |
lars |
1 |
/**
|
|
|
2 |
* When dealing with computer file sizes, it is common to append a post fix
|
|
|
3 |
* such as KB, MB or GB to a string in order to easily denote the order of
|
|
|
4 |
* magnitude of the file size. This plug-in allows sorting to take these
|
|
|
5 |
* indicates of size into account. A counterpart type detection plug-in
|
|
|
6 |
* is also available.
|
|
|
7 |
*
|
|
|
8 |
* @name File size
|
|
|
9 |
* @summary Sort abbreviated file sizes correctly (8MB, 4KB etc)
|
|
|
10 |
* @author _anjibman_
|
|
|
11 |
*
|
|
|
12 |
* @example
|
|
|
13 |
* $('#example').dataTable( {
|
|
|
14 |
* columnDefs: [
|
|
|
15 |
* { type: 'file-size', targets: 0 }
|
|
|
16 |
* ]
|
|
|
17 |
* } );
|
|
|
18 |
*/
|
|
|
19 |
|
|
|
20 |
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
|
|
|
21 |
"file-size-pre": function ( a ) {
|
|
|
22 |
var x = a.substring(0,a.length - 2);
|
|
|
23 |
|
|
|
24 |
var x_unit = (a.substring(a.length - 2, a.length) == "MB" ?
|
|
|
25 |
1000 : (a.substring(a.length - 2, a.length) == "GB" ? 1000000 : 1));
|
|
|
26 |
|
|
|
27 |
return parseInt( x * x_unit, 10 );
|
|
|
28 |
},
|
|
|
29 |
|
|
|
30 |
"file-size-asc": function ( a, b ) {
|
|
|
31 |
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
|
|
|
32 |
},
|
|
|
33 |
|
|
|
34 |
"file-size-desc": function ( a, b ) {
|
|
|
35 |
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
|
|
|
36 |
}
|
|
|
37 |
} );
|