OrderBy: sort by user-selected predicate and predefined secondary

I am trying to sort the result table first by the user selected by the predicate and then by the predefined secondary.

For example, my ng-repeat is configured as follows:

<tr ng-repeat="line in model.resultList | orderBy:['-predicate', 'secondary_value'] | limitTo:model.pageSize:model.beginFrom">

... where the predicate is defined in the controller scope as $scope.predicate, and there is logic that changes this name based on user options.

I can sort without problems, just using the predicate myself (for example, orderBy:predicate:reverse)

Am I approaching this wrong? Are $ scope values ​​allowed in the orderBy array?

+4
source share
1 answer

. , $scope

orderBy: [predicate, 'secondary_value']

, [-predicate] . ( $scope), $scope.predicate , : $scope.predicate = '-name';

fiddle

+1

Source: https://habr.com/ru/post/1613214/


All Articles