esvit / ng-table

Simple table with sorting and filtering on AngularJS
http://esvit.github.io/ng-table
BSD 3-Clause "New" or "Revised" License
2.77k stars 851 forks source link

Multiple Column Sortable #629

Open IntelvsAMD opened 9 years ago

IntelvsAMD commented 9 years ago

This was posted a while ago, and I believe that it was fixed. https://github.com/esvit/ng-table/issues/160

   var data = [
     { name: 'lincoln',    birth: 1809, death: 1865 },
     { name: 'fdr',        birth: 1882, death: 1945 },
     { name: 'washington', birth: 1732, death: 1799 },
    { name: 'jfk',        birth: 1917, death: 1963 },
    { name: 'darwin',     birth: 1809, death: 1882 },
    { name: 'poe',        birth: 1809, death: 1849 }
   ];

   $scope.table = new ngTableParams({sorting: {name: 'asc'}}, {
       total: data.length,
       getData: function($defer, params) {
       $defer.resolve($filter('orderBy')(data, params.orderBy()));
   }});
<table ng-table='table'>
  <tr ng-repeat='row in $data'>
    <td data-title='Name' sortable="'name'">{{row.name}}</td>
    <td data-title='Lifespan' sortable="['birth', 'death']">{{row.birth}} - {{row.death}}</td>
  </tr>
</table>

This would result in:

Sorting: { "birth,death": "asc" }
IntelvsAMD commented 9 years ago

A small fix for this would be

            if (tempOrderBy.indexOf('+birth') > -1 || tempOrderBy.indexOf('-birth') > -1) {
                tempOrderBy.push('+death');
            }

This makes testing harder though.