ravid7000 / table-sortable

A jquery plugin to sort and paginate data in table form.
https://table-sortable.now.sh
MIT License
35 stars 14 forks source link

Problem sorting numbers #19

Open peter-walter opened 3 years ago

peter-walter commented 3 years ago

I have the following simplified configuration

        var columns = {
            name: 'Name',
            count: 'Count'
        };

        var data = [
            { name: 'D', count: '0' },
            { name: 'A', count: '16' },
            { name: 'B', count: '151' },
            { name: 'C', count: '11' },
            { name: 'F', count: '44' },
            { name: 'E', count: '5' }
        ];  

        var table = jQuery('#table-sortable').tableSortable({
            data: data,
            columns: columns,
            pagination: false
        });

When sorting against the 'count' column you will see the numbers 151 and 44 are incorrectly sorted. image image

I have tried removing the quotes around the numbers, however the number zero then presents a problem and fires an exception: image

Any help gratefully received.

peter-walter commented 3 years ago

On further investigation

eg

        var data = [
            { name: 'D', count: 0 },
            { name: 'A', count: 16 },
            { name: 'B', count: 151 },
            { name: 'C', count: 11 },
            { name: 'F', count: 44 },
            { name: 'E', count: 5 }
        ];  

will throw the error in the console.

If you engineer the list to have a non-zero (positive or negative) at the top of the column, then the sort works fine.

ali0une commented 2 months ago

i had to hack a bit as my knowledge of webpack and node is really limited and i don't understand how to get a maxified version of the table-sortable.min.js ... but i managed to get something readable and i added a NaturalSort function that fix the sorting of items in the list. Please check the enclosed modified table-sortable-naturalSort-max.js table-sortable-naturalSort-max.zip

This code is under WTFPL.

Many thanks @ravid7000 for this great jQuery plugin that is perfect for my inventory project btw.