I am using angular orderby with the custom function. It looks like this:
Objects:
$scope.array = [{'field1': some_value,
'field2': some_value,
...
'field10': some_value},
...
{'field1': some_value,
...
'field10': some_value} // Field can be more in the future
]
Controller:
$scope.array = $filter('orderBy')($scope.array, [function(item) {
return customOrderFunction(item);
}, 'field1', 'field2', 'field3', 'field4', 'field5',...,'field10']);
But it's not pretty && the field can be more in the future. I try to make a string to reduce the code size.
var fieldString = ['field1', 'field2', ... 'field10'];
$scope.array = $filter('orderBy')($scope.array, [function(item) {
return customOrderFunction(item);
}, fieldString.join()]);
But it gives an error. Is there any possible way to achieve this with orderBy? Or is there possible way to do this with JavaScript?
sort
with a custom sort function instead?orderBy
doesn't appear to have any special behaviour that you can't do withsort
. – miqid Aug 1 '14 at 0:38