Skip to content
This repository has been archived by the owner on Jun 22, 2019. It is now read-only.

Comparator for formated number strings #74

Open
julius-datajunkie opened this issue Jun 21, 2018 · 0 comments
Open

Comparator for formated number strings #74

julius-datajunkie opened this issue Jun 21, 2018 · 0 comments

Comments

@julius-datajunkie
Copy link

Currently, the sortable=True option only sorts when the columns are in raw number. Any formatting that turns that numbers into string will yield erroneous order.

For instance, 12.5% will be ranked higher than 2.1% when sorted in descending order, because the first character 1 is smaller than 2. To fix this I have locally modified the sort.js file as follow:

import R from 'ramda';

export default function sortRows(rows, sortColumn, sortDirection) {
    function comparer(a, b) {
        x = parseFloat(a[sortColumn]);
        y = parseFloat(b[sortColumn]);
        if (sortDirection === 'ASC') {
            if isNan(x):
                return (a[sortColumn] > b[sortColumn]) ? 1 : -1;
            else:
                return (x > y) ? 1 : -1;
        } else if (sortDirection === 'DESC') {
            if isNan(x):
                return (a[sortColumn] < b[sortColumn]) ? 1 : -1;
            else:
                return (x < y) ? 1 : -1;
        }
    }
    return (sortDirection === 'NONE' ?
        rows : R.sort(comparer, rows.slice(0))
    );
}

Nonetheless, this doesn't seem to fix the problem. Are there any patch planned for this feature?

Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant