You need to make use of a custom sorting function - http://datatables.net/plug-ins . I don't think there is one already written from Brazilian formatting, but I think it will be fairly easy for you to modify the "comma's for decimal place" one to match your needs.
Okay - let's take the comma's for decimal place example. What you need to do is first remove the '.'s in your numbers and then change the ','s into dots. Here is an example for the ascending function:
[code]
jQuery.fn.dataTableExt.oSort['brazilian-asc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /./, "" ).replace( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /./, "" ).replace( /,/, "." );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
[/code]
See how you go with that.
thank you Allan ...
sorry that did not work did not know if something wrong
was so
[code]
jQuery.fn.dataTableExt.oSort['brazilian-asc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /./, "" ).replace( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /./, "" ).replace( /,/, "." );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['brazilian-desc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /./, "" ).replace( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /./, "" ).replace( /,/, "." );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
[/code]
and page
{ "bSortable": true, "sType": "brazilian" },
[code]
jQuery.fn.dataTableExt.oSort['brazilian-asc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /\./, "" ).replace( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /\./, "" ).replace( /,/, "." );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['brazilian-desc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /\./, "" ).replace( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /\./, "" ).replace( /,/, "." );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
[/code]
I think I had an error in my example - the '.' needs to be escaped in the search! Try that.
Replies
You need to make use of a custom sorting function - http://datatables.net/plug-ins . I don't think there is one already written from Brazilian formatting, but I think it will be fairly easy for you to modify the "comma's for decimal place" one to match your needs.
Regards,
Allan
was exactly what I imagined Sorting modify the decimal place, but I work with php I do not know how this change ... Someone there can help me?
Okay - let's take the comma's for decimal place example. What you need to do is first remove the '.'s in your numbers and then change the ','s into dots. Here is an example for the ascending function:
[code]
jQuery.fn.dataTableExt.oSort['brazilian-asc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /./, "" ).replace( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /./, "" ).replace( /,/, "." );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
[/code]
See how you go with that.
Allan
sorry that did not work did not know if something wrong
was so
[code]
jQuery.fn.dataTableExt.oSort['brazilian-asc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /./, "" ).replace( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /./, "" ).replace( /,/, "." );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['brazilian-desc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /./, "" ).replace( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /./, "" ).replace( /,/, "." );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
[/code]
and page
{ "bSortable": true, "sType": "brazilian" },
sorry to bothered, you are very nice
[code]
jQuery.fn.dataTableExt.oSort['brazilian-asc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /\./, "" ).replace( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /\./, "" ).replace( /,/, "." );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['brazilian-desc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /\./, "" ).replace( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /\./, "" ).replace( /,/, "." );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
[/code]
I think I had an error in my example - the '.' needs to be escaped in the search! Try that.
Allan
Thank you for all your assistance.
I truly appreciate your help in resolving the problem.
I made a update in your function to work fine with values over 999.999,99
[code]
jQuery.fn.dataTableExt.oSort['brazilian-asc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /\./g, "" ).replace( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /\./g, "" ).replace( /,/, "." );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['brazilian-desc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /\./g, "" ).replace( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /\./g, "" ).replace( /,/, "." );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
[/code]
Wilson Rocha Neto
Allan