1

I have a simple inbox table which consists of mails that have mailtext, sender and date attributes. I want this table to be sortable in terms of every one of these attributes when clicked to correspondent table header. Right now I am only trying to order this table in terms of sender attribute. I am using AngularJS 'orderBy' filter but nothing changes in the table. What is wrong with my code?

HTML Code Snippet:

<div class="container">
  <h2>Your Inbox</h2><br><br>
  <table ng-show="showInboxTable" class="table table-hover">
    <thead>
      <tr>
        <th>Mail</th>
        <th ng-click="sortMailsSender()">Sender</th>
        <th>Date</th>
      </tr>
    </thead>
    <tbody>
      <tr ng-repeat="mail in mails">
        <td>{{mail.mailtext}}</td>
        <td>{{mail.sender}}</td>
        <td>{{mail.date}}</td>
      </tr>      
    </tbody>
  </table>
</div>

AngularJS Controller:

$scope.sortMailsSender = function()
{
    if ( !$window.sessionStorage.inboxCompare || $window.sessionStorage.inboxCompare == 'gt')
    {               
        console.log('filter straight'); 

        $filter('orderBy')($scope.mails, 'sender', false); 

        $window.sessionStorage.setItem('inboxCompare', 'lt');
    }
    else
    {                
        console.log('filter reverse'); 

        $filter('orderBy')($scope.mails, 'sender', true);

        $window.sessionStorage.setItem('inboxCompare', 'gt');
    }
}
1
  • Define "doesn't seem be working", precisely: what are you doing? What is your input? What is your output? Commented Jul 10, 2017 at 18:21

1 Answer 1

1

You should assign to your $scope.mails after applying filter and syntax should be

   $scope.mails = $filter('orderBy')($scope.mails , 'sender', false);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.