Sorting money values (BRL) not working very well

Sorting money values (BRL) not working very well

romulocpdromulocpd Posts: 9Questions: 0Answers: 0
edited September 2013 in Plug-ins
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

Replies

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    You need to remove the $ as well, since it is non-numeric.

    Allan
  • romulocpdromulocpd Posts: 9Questions: 0Answers: 0
    I've tried it too... but the problem continues...

    When I try sorting, the result is:

    1.345,65
    100,00
    100,00
    110,00
    135,00
    15,00
    150,00
  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    Please link to the page so we can take a look.

    Also, have you set the sType for the column?

    Allan
  • romulocpdromulocpd Posts: 9Questions: 0Answers: 0
    I don't use this feature because I use DataTables via class for all tables in my project.

    I've tried use auto detection, but won't work. With date columns, auto detection worked fine.
  • romulocpdromulocpd Posts: 9Questions: 0Answers: 0
    With type detection I guess it should to work. If the sorting by money won't work, I won't still using datatables.... Any help?!
  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    Again please link to the page so we can take a look. I'm afraid I don't know why it isn't working - it looks like it should.

    Allan
  • romulocpdromulocpd Posts: 9Questions: 0Answers: 0
    Hello,
    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!!!
  • romulocpdromulocpd Posts: 9Questions: 0Answers: 0
    Problem solved.

    var xx = (a == "-") ? 0 : a.replace(".", "");
    var yy = (b == "-") ? 0 : b.replace(".", "");

    var x = (a == "-") ? 0 : xx.replace(/,/, ".");
    var y = (b == "-") ? 0 : yy.replace(/,/, ".");
This discussion has been closed.