AngularJS - Sort multiple columns including the date in string format

48 views
Skip to first unread message

Aravind Subramanian

unread,
May 20, 2015, 7:45:38 AM5/20/15
to ang...@googlegroups.com
Is it possible to manipulate and sort multiple column in angularjs filter orderBy?

Fiddle

JS

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

function MyCtrl($scope, $filter) {
    var r = [
        {'group':1,'sub':1, 'date': '11/4/2014 2:01 PM'}, 
        {'group':2,'sub':10, 'date': '11/4/2014 4:36 PM'}, 
        {'group':1,'sub':2, 'date': '11/4/2014 8:59 AM'},
        {'group':1,'sub':20, 'date': '4/14/2015 5:54 PM'},
        {'group':2,'sub':1, 'date': '11/3/2014 9:09 PM'},
        {'group':2,'sub':11, 'date': '9/4/2014 2:48 PM'}
    ];

    $scope.mcards = $filter('orderBy')(r, [function(a){
        return -new Date(a.date).getTime(); 
        //manipulate the string and then sort it by ascending or descending order.
    }]);
}

It is not working as expected whereas when I try it in the following way it works great,

$scope.mcards = $filter('orderBy')(r, ['group', function(a){
    return -a.sub;
}]);

What is the problem here, am I missing something?

Thanks in advance.

Reply all
Reply to author
Forward
0 new messages