Bug in the Alt string plugin
Bug in the Alt string plugin
Hi everyone,
There is a bug with the 'alt-string' sorting function in the "sorting" plugin:
[code]
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"alt-string-pre": function ( a ) {
return a.match(/alt="(.*?)"/)[1].toLowerCase();
},
"alt-string-asc": function( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"alt-string-desc": function(a,b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
[/code]
I think it works well if all cells have an image, but if one doesn't (and it surely may happen), it breaks the code, saying:
[quote]a.match(...) is null[/quote]
It's because a is an empty string if the cell is empty. It may happen, for instance, when you have a column containing ticks but no crosses (better for readability). So as a quick workaround I did this:
[code]
"alt-string-pre": function ( a ) {
if (a == "") value = "zzz";
else value = a.match(/alt="(.*?)"/)[1];
return value.toLowerCase();
}
[/code]
Of course it's a quick fix and if one has a better solution, I'll be glad to hear it.
Bybye,
Kulgar.
There is a bug with the 'alt-string' sorting function in the "sorting" plugin:
[code]
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"alt-string-pre": function ( a ) {
return a.match(/alt="(.*?)"/)[1].toLowerCase();
},
"alt-string-asc": function( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"alt-string-desc": function(a,b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
[/code]
I think it works well if all cells have an image, but if one doesn't (and it surely may happen), it breaks the code, saying:
[quote]a.match(...) is null[/quote]
It's because a is an empty string if the cell is empty. It may happen, for instance, when you have a column containing ticks but no crosses (better for readability). So as a quick workaround I did this:
[code]
"alt-string-pre": function ( a ) {
if (a == "") value = "zzz";
else value = a.match(/alt="(.*?)"/)[1];
return value.toLowerCase();
}
[/code]
Of course it's a quick fix and if one has a better solution, I'll be glad to hear it.
Bybye,
Kulgar.
This discussion has been closed.
Replies
Allan
So here is the improvement:
[code]
"alt-string-pre": function ( a ) {
if (a.match(/alt="(.*?)"/) === null)
if (a === "") value = "zzz";
else value = a;
// or "zza" if you don't want to take the text into account for sorting the column
else value = a.match(/alt="(.*?)"/)[1];
return value.toLowerCase();
},
[/code]