0

In the following case orderBy filter is not working for point property and name. i don't know why? here is my example on fiddle.

Template:

<div ng-controller="AppCtrl">
    <table>
        <tr>
            <th style="width:100px;" ng-click="pred='name'">name</th>
            <th style="width:100px;">id</th>
            <th style="width:100px;" ng-click="pred='points'">point</th>
        </tr>
        <tbody ng-repeat="user in ranking | orderBy:pred">
        <tr ng-repeat="tab in user.tabs | orderBy:pred">
            <td style="width:100px;">{{user.name}}</td>
            <td style="width:100px;">{{tab.tabId}}</td>
            <td style="width:100px;">{{tab.points}}</td>
        </tr>
        </tbody>
    </table> 
</div>

Controller:

var app = angular.module('app', []);

function AppCtrl($scope) {
    $scope.currentTab = 1
    $scope.ranking = [
        {
            'uId': 2,
            'name': 'Jeremy',
            'tabs': [
                {
                    'tabId': 1,
                    'points': 100,
                }, 
                {
                    'tabId': 2,
                    'points': 10
                }
            ],
        },
        {
            'uId': 3,
            'name': 'Jordon',
            'tabs': [
                {
                    'tabId': 1,
                    'points': 180,
                },
                {
                    'tabId': 2,
                    'points': 5
                }
            ],
        }
    ]
}
Mukund Kumar
  • 21,413
  • 18
  • 59
  • 79
  • You'll have to define a specific sort function. Nice example [here][1] [1]: http://stackoverflow.com/questions/23723417/how-to-orderby-in-angularjs-using-nested-property – Dominic Scanlan Apr 13 '15 at 08:29
  • How do you expect angular to sort with 'point' ? when nothing is called 'point' ? – yunandtidus Apr 13 '15 at 11:13
  • that was my spelling mistake @yunandtidus, but even it is not working – Mukund Kumar Apr 13 '15 at 11:20
  • How do you expect angular to sort by point, when there are several points in each items ? You need to implement a compare function here : https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Array/sort – yunandtidus Apr 13 '15 at 12:06

0 Answers0