Sorting money values (BRL) not working very well
Sorting money values (BRL) not working very well
Hello.
I'm from Brazil and the currency format here is diferent from others places. Example: $5,233.12 is R$ 5.233,12
I'm using plugin numeric-comma. If the values in my grid are between 0 and 999, the plugin works perfect! But if any value was more 999, the sorting don't work.
The problem is with , and . I tried to modify the plugin like above, but don't works.:
[code]
jQuery.fn.dataTableExt.oSort['numeric-comma-asc'] = function (a, b) {
a = a.replace(".", "");
b = b.replace(".", "");
var x = (a == "-") ? 0 : a.replace(/,/, ".");
var y = (b == "-") ? 0 : b.replace(/,/, ".");
x = parseFloat(x);
y = parseFloat(y);
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
[/code]
I've tried replace . with space before the process, but it won't work......
Any sugestions?????
Thank you
Romulo
I'm from Brazil and the currency format here is diferent from others places. Example: $5,233.12 is R$ 5.233,12
I'm using plugin numeric-comma. If the values in my grid are between 0 and 999, the plugin works perfect! But if any value was more 999, the sorting don't work.
The problem is with , and . I tried to modify the plugin like above, but don't works.:
[code]
jQuery.fn.dataTableExt.oSort['numeric-comma-asc'] = function (a, b) {
a = a.replace(".", "");
b = b.replace(".", "");
var x = (a == "-") ? 0 : a.replace(/,/, ".");
var y = (b == "-") ? 0 : b.replace(/,/, ".");
x = parseFloat(x);
y = parseFloat(y);
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
[/code]
I've tried replace . with space before the process, but it won't work......
Any sugestions?????
Thank you
Romulo
This discussion has been closed.
Replies
Allan
When I try sorting, the result is:
1.345,65
100,00
100,00
110,00
135,00
15,00
150,00
Also, have you set the sType for the column?
Allan
I've tried use auto detection, but won't work. With date columns, auto detection worked fine.
Allan
So my system is at:
http://gestorweb.sdplus.com.br
LOGIN: admin
SENHA: 123 (password)
CHAVE: LOJA001 (key)
After logon, please access:
http://gestorweb.sdplus.com.br/Financeiro/ContasAPagar/Listar
Click on button Filtrar (Filter). The result will be showed.
Please click on column Valor (Value of the bill).
In this moment you will can the problem on sorting. With sorting of date columns the problem is ok.
On the source code of the page, find by >Money values Datatables.net<.
I've used 2 features: type detection (comma-values) e o sorting for this type.
If you filter by values between 1 and 999, the sorting works very well, but with values above 1000 the problems occours.
Thank you!!!
var xx = (a == "-") ? 0 : a.replace(".", "");
var yy = (b == "-") ? 0 : b.replace(".", "");
var x = (a == "-") ? 0 : xx.replace(/,/, ".");
var y = (b == "-") ? 0 : yy.replace(/,/, ".");