filamentgroup / tablesaw

A group of plugins for responsive tables.
MIT License
5.48k stars 434 forks source link

Natural sort is not working in tablesaw #226

Closed erakashpatel closed 8 years ago

erakashpatel commented 8 years ago

I need help in tablesaw natural sort

https://filamentgroup.github.io/tablesaw/demo/sort-custom.html html.

and i want to natural sort works here.

HERE is the my code.

  
            
            
            
            
            
            
            
            

Sortable Table

Movie Title Rank Year Rating Gross Sort
Avatar 1 11/2009 83% 2.7B test 1
Titanic 2 12/1997 88% 2.1B test 3
The Avengers 3 3/2012 92% 1.5B test 60
Harry Potter and the Deathly Hallows—Part 2 4 5/2011 96% 1.3B test 15
Frozen 5 9/2013 89% 1.2B test 9
Iron Man 3 6 1/2013 78% 1.2B test 4
Transformers: Dark of the Moon 7 3/2011 36% 1.1Btest 3
The Lord of the Rings: The Return of the King 8 4/2003 95% 1.1B test 2
Skyfall 9 11/2012 92% 1.1B test 22
Transformers: Age of Extinction 10 12/2014 18% 1.0B test 11111
        <link rel="stylesheet" href="https://filamentgroup.github.io/tablesaw/demo/demo.css">
        <link rel="stylesheet" href="https://filamentgroup.github.io/demo-head/demohead.css">
        <script src="https://filamentgroup.github.io/tablesaw/dist/dependencies/jquery.js"></script>
        <script src="https://filamentgroup.github.io/tablesaw/dist/tablesaw.js"></script>
        <script src="https://filamentgroup.github.io/tablesaw/dist/tablesaw-init.js"></script>
        <script src="//filamentgroup.github.io/demo-head/loadfont.js"></script>
        <script>
        $(function() {
                $( "#custom-sort" ).data( "tablesaw-sort", function( ascending ) {
                    return function( a, b ) {
                        var yearA = a.cell.split( "/" ),
                            yearB = b.cell.split( "/" );
                        if( ascending ) {
                            return parseInt( yearA[ 1 ], 10 ) - parseInt( yearB[ 1 ], 10 );
                        } else {
                            // descending
                            return parseInt( yearB[ 1 ], 10 ) - parseInt( yearA[ 1 ], 10 );
                        }
                    };
                });
            });
        $(function() {
            $( "#custom-sort1" ).data( "tablesaw-sort", function( ascending ) {
                return function( a, b ) { // HERE need some thing sorting.
                };
            });
        });
        </script>
        <div class="demo-header">
        <div class="company">
        <img src="http://filamentgroup.com/images/fg-logo-positive-sm-crop.png">
        </div>

        </div>
        <div class="docs-main">
        <h2>Sortable Table</h2>
        <table class="tablesaw" data-tablesaw-sortable data-tablesaw-sortable-switch>
        <thead>
        <tr>
        <th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="persist">Movie Title</th>
        <th scope="col" data-tablesaw-sortable-col data-tablesaw-sortable-default-col data-tablesaw-priority="3">Rank</th>
        <th id="custom-sort" scope="col" data-tablesaw-sortable-col data-tablesaw-priority="2">Year</th>
        <th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="1"><abbr title="Rotten Tomato Rating">Rating</abbr></th>
        <th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="4">Gross</th>
        <th id="custom-sort1" scope="col" data-tablesaw-sortable-col data-tablesaw-priority="5">Sort</th>
        </tr>
        </thead>
        <tbody>
        <tr>
        <td class="title"><a href="http://en.wikipedia.org/wiki/Avatar_(2009_film)">Avatar</a></td>
        <td>1</td>
        <td>11/2009</td>
        <td>83%</td>
        <td>2.7B</td>
        <td>test 1</td>
        </tr>
        <tr>
        <td class="title"><a href="http://en.wikipedia.org/wiki/Titanic_(1997_film)">Titanic</a></td>
        <td>2</td>
        <td>12/1997</td>
        <td>88%</td>
        <td>2.1B</td>
        <td>test 3</td>
        </tr>
        <tr>
        <td class="title"><a href="http://en.wikipedia.org/wiki/The_Avengers_(2012_film)">The Avengers</a></td>
        <td>3</td>
        <td>3/2012</td>
        <td>92%</td>
        <td>1.5B</td>
        <td>test 60</td>
        </tr>
        <tr>
        <td class="title"><a href="http://en.wikipedia.org/…/Harry_Potter_and_the_Deathly_Hall…">Harry Potter and the Deathly Hallows—Part 2</a></td>
        <td>4</td>
        <td>5/2011</td>
        <td>96%</td>
        <td>1.3B</td>
        <td>test 15</td>
        </tr>
        <tr>
        <td class="title"><a href="http://en.wikipedia.org/wiki/Frozen_(2013_film)">Frozen</a></td>
        <td>5</td>
        <td>9/2013</td>
        <td>89%</td>
        <td>1.2B</td>
        <td>test 9</td>
        </tr>
        <tr>
        <td class="title"><a href="http://en.wikipedia.org/wiki/Iron_Man_3">Iron Man 3</a></td>
        <td>6</td>
        <td>1/2013</td>
        <td>78%</td>
        <td>1.2B</td>
        <td>test 4</td>
        </tr>
        <tr>
        <td class="title"><a href="http://en.wikipedia.org/wiki/Transformers:_Dark_of_the_Moon">Transformers: Dark of the Moon</a></td>
        <td>7</td>
        <td>3/2011</td>
        <td>36%</td>
        <td>1.1B</td><td>test 3</td>
        </tr>
        <tr>
        <td class="title"><a href="http://en.wikipedia.org/…/The_Lord_of_the_Rings:_The_Return…">The Lord of the Rings: The Return of the King</a></td>
        <td>8</td>
        <td>4/2003</td>
        <td>95%</td>
        <td>1.1B</td>
        <td>test 2</td>
        </tr>
        <tr>
        <td class="title"><a href="http://en.wikipedia.org/wiki/Skyfall">Skyfall</a></td>
        <td>9</td>
        <td>11/2012</td>
        <td>92%</td>
        <td>1.1B</td>
        <td>test 22</td>
        </tr>
        <tr>
        <td class="title"><a href="http://en.wikipedia.org/wiki/Transformers:_Age_of_Extinction">Transformers: Age of Extinction</a></td>
        <td>10</td>
        <td>12/2014</td>
        <td>18%</td>
        <td>1.0B</td>
        <td>test 11111</td>
        </tr>
        </tbody>
        </table>
        </div>

When you click on last sort column head "sort" then natural sort is not works..

Its sholud be : test 1 test 2 test 3 test 3 test 4 test 9 test 15 test 22 test 60 test 11111

Theophilix commented 8 years ago

Via Bountysource I offer 50$ for this issue: https://www.bountysource.com/issues/36860904-natural-sort-is-not-working-in-tablesaw. I want natural sorting to work in table saw like it does here: https://github.com/overset/javascript-natural-sort.

zachleat commented 8 years ago

I would recommend integrating something like https://github.com/Bill4Time/javascript-natural-sort with tablesaw’s custom sort function feature. I’ve wired up an example here: https://github.com/filamentgroup/tablesaw/blob/master/demo/sort-natural.html