| 8 |
lars |
1 |
/**
|
|
|
2 |
* Although DataTables' internal numeric sorting works no problem on negative
|
|
|
3 |
* numbers, it does not accept positively signed numbers. This plug-in will
|
|
|
4 |
* sort just such data numerically.
|
|
|
5 |
*
|
|
|
6 |
* @name Fully signed numbers sorting
|
|
|
7 |
* @summary Sort data numerically with a leading `+` symbol (as well as `-`).
|
|
|
8 |
* @author [Allan Jardine](http://sprymedia.co.uk)
|
|
|
9 |
*
|
|
|
10 |
* @example
|
|
|
11 |
* $('#example').dataTable( {
|
|
|
12 |
* columnDefs: [
|
|
|
13 |
* { type: 'signed-num', targets: 0 }
|
|
|
14 |
* ]
|
|
|
15 |
* } );
|
|
|
16 |
*/
|
|
|
17 |
|
|
|
18 |
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
|
|
|
19 |
"signed-num-pre": function ( a ) {
|
|
|
20 |
return (a=="-" || a==="") ? 0 : a.replace('+','')*1;
|
|
|
21 |
},
|
|
|
22 |
|
|
|
23 |
"signed-num-asc": function ( a, b ) {
|
|
|
24 |
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
|
|
|
25 |
},
|
|
|
26 |
|
|
|
27 |
"signed-num-desc": function ( a, b ) {
|
|
|
28 |
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
|
|
|
29 |
}
|
|
|
30 |
} );
|