-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsorting.currency.js
More file actions
47 lines (37 loc) · 1.4 KB
/
sorting.currency.js
File metadata and controls
47 lines (37 loc) · 1.4 KB
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
37
38
39
40
41
42
43
44
45
46
47
/*globals $ */
$.fn.dataTableExt.oSort['currency-asc'] = function (a, b) {
'use strict';
var x, y;
/* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */
x = (a === "-" || a === "--" || a === '' || a.toLowerCase().replace('/', '') === 'na') ? -1 : a.replace(/,/g, "");
y = (b === "-" || b === "--" || b === '' || b.toLowerCase().replace('/', '') === 'na') ? -1 : b.replace(/,/g, "");
/* Remove the currency sign */
if (typeof x === "string" && isNaN(x.substr(0, 1), 10)) {
x = x.substring(1);
}
if (typeof y === "string" && isNaN(y.substr(0, 1), 10)) {
y = y.substring(1);
}
/* Parse and return */
x = parseFloat(x, 10);
y = parseFloat(y, 10);
return x - y;
};
$.fn.dataTableExt.oSort['currency-desc'] = function (a, b) {
'use strict';
var x, y;
/* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */
x = (a === "-" || a === "--" || a === '' || a.toLowerCase().replace('/', '') === 'na') ? -1 : a.replace(/,/g, "");
y = (b === "-" || b === "--" || b === '' || b.toLowerCase().replace('/', '') === 'na') ? -1 : b.replace(/,/g, "");
/* Remove the currency sign */
if (typeof x === "string" && isNaN(x.substr(0, 1), 10)) {
x = x.substring(1);
}
if (typeof y === "string" && isNaN(y.substr(0, 1), 10)) {
y = y.substring(1);
}
/* Parse and return */
x = parseFloat(x, 10);
y = parseFloat(y, 10);
return y - x;
};