| 4 |
lars |
1 |
/**
|
|
|
2 |
* This plug-in will provide numeric sorting for currency columns (either
|
|
|
3 |
* detected automatically with the currency type detection plug-in or set
|
|
|
4 |
* manually) while taking account of the currency symbol ($ or £ by default).
|
|
|
5 |
*
|
|
|
6 |
* DataTables 1.10+ has currency sorting abilities built-in and will be
|
|
|
7 |
* automatically detected. As such this plug-in is marked as deprecated, but
|
|
|
8 |
* might be useful when working with old versions of DataTables.
|
|
|
9 |
*
|
|
|
10 |
* @name Currency
|
|
|
11 |
* @summary Sort data numerically when it has a leading currency symbol.
|
|
|
12 |
* @deprecated
|
|
|
13 |
* @author [Allan Jardine](http://sprymedia.co.uk)
|
|
|
14 |
*
|
|
|
15 |
* @example
|
|
|
16 |
* $('#example').dataTable( {
|
|
|
17 |
* columnDefs: [
|
|
|
18 |
* { type: 'currency', targets: 0 }
|
|
|
19 |
* ]
|
|
|
20 |
* } );
|
|
|
21 |
*/
|
|
|
22 |
|
|
|
23 |
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
|
|
|
24 |
"currency-pre": function ( a ) {
|
|
|
25 |
a = (a==="-") ? 0 : a.replace( /[^\d\-\.]/g, "" );
|
|
|
26 |
return parseFloat( a );
|
|
|
27 |
},
|
|
|
28 |
|
|
|
29 |
"currency-asc": function ( a, b ) {
|
|
|
30 |
return a - b;
|
|
|
31 |
},
|
|
|
32 |
|
|
|
33 |
"currency-desc": function ( a, b ) {
|
|
|
34 |
return b - a;
|
|
|
35 |
}
|
|
|
36 |
} );
|