-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumber-comma.js
37 lines (32 loc) · 954 Bytes
/
number-comma.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* This DataTables plugin sorts a numeric column with price link.
* Cells can include a link and a EUR sign.
*
* @name numeric-comma
* @summary Sort columns with numeric value using comma as decimal separator.
* @author [Pekka Huhtala]
*
* @example
* $('#example').dataTable( {
* columnDefs: [
* { type: 'numeric-comma', targets: 0 },
* ]
* } );
*/
jQuery.fn.dataTableExt.oSort['numeric-comma-pre'] = function (a, b) {
a = $(a).text().replace("€", "");
a = $.trim(a);
var x = (a == "-") ? 0 : a.replace(/,/, ".");
x = parseFloat(x);
return x;
}
jQuery.fn.dataTableExt.oSort['numeric-comma-asc'] = function (a, b) {
x = parseFloat(a);
y = parseFloat(b);
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['numeric-comma-desc'] = function (a, b) {
x = parseFloat(a);
y = parseFloat(b);
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};