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
                }
            ],
        }
    ]
}
4
  • You'll have to define a specific sort function. Nice example [here][1] [1]: stackoverflow.com/questions/23723417/… Commented Apr 13, 2015 at 8:29
  • How do you expect angular to sort with 'point' ? when nothing is called 'point' ? Commented Apr 13, 2015 at 11:13
  • that was my spelling mistake @yunandtidus, but even it is not working Commented Apr 13, 2015 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 : developer.mozilla.org/fr/docs/Web/JavaScript/Reference/… Commented Apr 13, 2015 at 12:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.