Existe um bug quando ordenamos numero com o uso da biblioteca javascript jQuery, o bug ocorre quando o primeiro item começa com "0". Os números são interpretados como texto e no final você terá uma sequência completamente errada parecida com a sequência abaixo 1, 10, 2, 3, 31 etc. A solução é simples, basta alterar a expressão regular isDigit no arquivo javascript tablesorter.js para a expressão abaixo:
this.isDigit = function(s, config) {
var exp= '/(\0)|(^[+]?0(\.0+)?$)|(^([-+]?[1-9][0-9]*)$)|(^([-+]?((0?|[1-9][0-9]*)\.([0-9]*)))$)|(^[-+]?[1-9]+[0-9]*\.0+$)/';
return RegExp(exp).test($.trim(s.replace(/,/g, '')));
//Has bug when 0 is first digit in list and interprets as text.
//http://groups.google.com/group/jquery-dev/browse_thread/thread/d8e75a30f7ca3067
//var DECIMAL = '\\' + config.decimal;
//var exp = '/(^[+]?0(' + DECIMAL + '0+)?$)|(^([-+]?[1-9][0-9]*)$)|(^([-+]?((0?|[1-9][0-9]*)' + DECIMAL + '(0*[1-9][0-9]*)))$)|(^[-+]?[1-9]+[0-9]*' + DECIMAL + '0+$)/';
//return RegExp(exp).test($.trim(s));
};
There is a bug when sorting numbers when the first item in the table is a "0". The numbers are interpreted as text instead of digits and you will end up with a sequence like 1, 10, 2, 3, 31 etc. I found the solution in this jquery mailing list thread which uses a different regular expression in the isDigit function in the tablesorter.js plugin.
this.isDigit = function(s, config) {
var exp= '/(\0)|(^[+]?0(\.0+)?$)|(^([-+]?[1-9][0-9]*)$)|(^([-+]?((0?|[1-9][0-9]*)\.([0-9]*)))$)|(^[-+]?[1-9]+[0-9]*\.0+$)/';
return RegExp(exp).test($.trim(s.replace(/,/g, '')));
//Has bug when 0 is first digit in list and interprets as text.
//http://groups.google.com/group/jquery-dev/browse_thread/thread/d8e75a30f7ca3067
//var DECIMAL = '\\' + config.decimal;
//var exp = '/(^[+]?0(' + DECIMAL + '0+)?$)|(^([-+]?[1-9][0-9]*)$)|(^([-+]?((0?|[1-9][0-9]*)' + DECIMAL + '(0*[1-9][0-9]*)))$)|(^[-+]?[1-9]+[0-9]*' + DECIMAL + '0+$)/';
//return RegExp(exp).test($.trim(s));
};
Assinar:
Postar comentários (Atom)
Nenhum comentário:
Postar um comentário