Bug Fix for Absolute sorting plugin

Bug Fix for Absolute sorting plugin

awelchawelch Posts: 38Questions: 1Answers: 3

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));
    };

Replies

  • awelchawelch Posts: 38Questions: 1Answers: 3

    This fix has been committed. This post can be deleted/closed.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @awelch ,

    Thanks for raising this one, closing now,

    Cheers,

    Colin

This discussion has been closed.