Bug Fix for Absolute sorting plugin
Bug Fix for Absolute sorting plugin
![awelch](https://secure.gravatar.com/avatar/4004709e4434943590d57819f3079414/?default=https%3A%2F%2Fvanillicon.com%2F4004709e4434943590d57819f3079414_200.png&rating=g&size=120)
There is a bug in the Absolute sorting plugin. The ordering methods are missing the equals case when checking the alwaysTop and alwaysBottom arrays. This causes the plugin to steamroll multi-column sorting. The ordering methods should be as follows:
// Ascending ordering method
o.asc = function ( a, b, isNumber ) {
if ( (o.alwaysTop[ a ] && o.alwaysTop[ b ]) ||
(o.alwaysBottom[ a ] && o.alwaysBottom[ b ]) ) {
return 0;
}
else if ( o.alwaysTop[ a ] || o.alwaysBottom[ b ] ) {
return -1;
}
else if ( o.alwaysBottom[ a ] || o.alwaysTop[ b ] ) {
return 1;
}
if ( isNumber ) {
// Cast as a number if required
if ( typeof a === 'string' ) {
a = a.replace(/[^\d\-\.]/g, '') * 1;
}
if ( typeof b === 'string' ) {
b = b.replace(/[^\d\-\.]/g, '') * 1;
}
}
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
};
// Descending ordering method
o.desc = function ( a, b, isNumber ) {
if ( (o.alwaysTop[ a ] && o.alwaysTop[ b ]) ||
(o.alwaysBottom[ a ] && o.alwaysBottom[ b ]) ) {
return 0;
}
else if ( o.alwaysTop[ a ] || o.alwaysBottom[ b ] ) {
return -1;
}
else if ( o.alwaysBottom[ a ] || o.alwaysTop[ b ] ) {
return 1;
}
if ( isNumber ) {
if ( typeof a === 'string' ) {
a = a.replace(/[^\d\-\.]/g, '') * 1;
}
if ( typeof b === 'string' ) {
b = b.replace(/[^\d\-\.]/g, '') * 1;
}
}
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
};
This discussion has been closed.
Replies
This fix has been committed. This post can be deleted/closed.
Hi @awelch ,
Thanks for raising this one, closing now,
Cheers,
Colin