My own sType seems not working

My own sType seems not working

dragonicflashdragonicflash Posts: 2Questions: 0Answers: 0
edited March 2014 in Plug-ins
Hi everyone.

I'm working with numbers which have a comma as thousands separator (ex: 52,691,252 / 1,005,579,411 / 900 / 90,282). There are all integers (no decimal). The default behavior of Datatables is to order them in considering the first coma. So, I decided to add a new sType : commasep, with functions following :

[code]
jQuery.fn.dataTableExt.oSort['commasep-asc'] = function(a,b) {
x = a.replace( /,/g, "" );
y = b.replace( /,/g, "" );
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};

jQuery.fn.dataTableExt.oSort['commasep-desc'] = function(a,b) {
x = a.replace( /,/g, "" );
y = b.replace( /,/g, "" );
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
[/code]

The principle is just removed commas to compare numbers. But... not working (the order is still wrong). So, I decided to put an "alert" in these functions above to see what I get in entry (a, b) and what's going out (x, y). But... no alert when I order my fields with sType "commasep".

So... I want to know if it's normal to not have the alert's result in putting alert in such functions, or if it means that the function is not used / launched for X reason...

Thanks by advance.

Replies

  • dylanmacdylanmac Posts: 49Questions: 7Answers: 1
    Which version of datatables are you using? I am having the exact problem with v. 1.10 beta 2. Allen seems to think it might be a bug in the code but I haven't heard back definitively.

    My question along these lines:
    http://www.datatables.net/forums/discussion/20076/using-plugins-in-1-10#Item_5
  • dragonicflashdragonicflash Posts: 2Questions: 0Answers: 0
    Hi there.

    Happy to see I am not the only one. =) I'm using the last stable version, 1.9.4. I'm hoping we will have some answers.
  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    It should work perfectly fine in 1.9.4. Example here: http://datatables.net/release-datatables/examples/plug-ins/sorting_sType.html .

    If it isn't working for you, please link to a test case showing the problem.

    Allan
This discussion has been closed.