| 8 |
lars |
1 |
/**
|
|
|
2 |
* An alternative to the formatted number sorting function above (particularly
|
|
|
3 |
* useful when considering localisation which uses dots / periods for 10^3
|
|
|
4 |
* separation rather than decimal places). Another method of overcoming it
|
|
|
5 |
* difficulties of sorting formatted numbers is to have the data to be sorted
|
|
|
6 |
* upon separate from the visual data. This sorting function pair will use the
|
|
|
7 |
* 'title' attribute of en empty span element (or anything else) to sort
|
|
|
8 |
* numerically (for example `<span title="1000000"><span>1'000'000`).
|
|
|
9 |
*
|
|
|
10 |
* Note that the HTML5 `data-sort` attribute can be [used to supply sorting data
|
|
|
11 |
* to DataTables](//datatables.net/manual/orthogonal-data) and is preferable to
|
|
|
12 |
* using this method, which is therefore marked as deprecated.
|
|
|
13 |
*
|
|
|
14 |
* @name Hidden title numeric sorting
|
|
|
15 |
* @summary Sort data numerically based on an attribute on an empty element.
|
|
|
16 |
* @deprecated
|
|
|
17 |
* @author [Allan Jardine](http://sprymedia.co.uk)
|
|
|
18 |
*
|
|
|
19 |
* @example
|
|
|
20 |
* $('#example').dataTable( {
|
|
|
21 |
* columnDefs: [
|
|
|
22 |
* { type: 'title-numeric', targets: 0 }
|
|
|
23 |
* ]
|
|
|
24 |
* } );
|
|
|
25 |
*/
|
|
|
26 |
|
|
|
27 |
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
|
|
|
28 |
"title-numeric-pre": function ( a ) {
|
|
|
29 |
var x = a.match(/title="*(-?[0-9\.]+)/)[1];
|
|
|
30 |
return parseFloat( x );
|
|
|
31 |
},
|
|
|
32 |
|
|
|
33 |
"title-numeric-asc": function ( a, b ) {
|
|
|
34 |
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
|
|
|
35 |
},
|
|
|
36 |
|
|
|
37 |
"title-numeric-desc": function ( a, b ) {
|
|
|
38 |
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
|
|
|
39 |
}
|
|
|
40 |
} );
|