Search code examples
angularjsmultiple-columnsangularjs-orderby

AngularJS: orderBy - string & array are not the same


I have an array of users:

$scope.users = [
  {name: 'Anh', age: 10},
  {name: 'Ánh', age: 10},
  {name: 'Ba' , age: 10}
]

When i use orderBy:'name' the result is:

  1. Anh
  2. Ánh
  3. Ba

but when i use multiple fields orderBy:['name','age'] the result is different:

  1. Anh
  2. Ba
  3. Ánh

Waiting for your help!


Solution

  • try this..

    var app = angular.module('filterSample', []);
    app.controller('filterCtrl', function ($scope) {
    
      $scope.data = {
        messages: ['first', 'second', '3rd', 'fourth', 'fifth']
      }
    
      $scope.startsWith = function (actual, expected) {
        var lowerStr = (actual + "").toLowerCase();
        return lowerStr.indexOf(expected.toLowerCase()) === 0;
      }
    });
    

    and html as

    <ul border="1px" ng-repeat="msg in data.messages | filter:search:startsWith">
          <li>{{msg}}</li>
        </ul>
    

    or check on this plunkr-http://plnkr.co/edit/gcVYfZXTqsDU1Z7REU2I?p=preview