# My own sType seems not working

# My own sType seems not working

dragonicflash
Posts: 2Questions: 0Answers: 0

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.

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.

This discussion has been closed.

## Replies

My question along these lines:

http://www.datatables.net/forums/discussion/20076/using-plugins-in-1-10#Item_5

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.

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

Allan