使用angularjs在表列上自定义排序和orderby

时间:2017-09-13 09:19:04

标签: angularjs

尝试对记录优先级列进行排序必须根据H-M-L-NO GO进行排序,反之亦然。试过但无法对prority列进行排序。

$scope.filterPriority = function () {
        if(toggled) {
            $scope.peoples.sort(function (a, b) {
                return (priorityArray[a.priority] || Infinity ) - (priorityArray[b.priority] || Infinity);
            });
            $scope.sortBy = 'priority';
            $scope.sortDescending = !$scope.sortDescending;
        } else {
            $scope.peoples.sort(function (a, b) {
                return (priorityArray[b.priority] || Infinity ) - (priorityArray[a.priority] || Infinity);
            });
            $scope.sortBy = 'priority';
            $scope.sortDescending = !$scope.sortDescending;
        }   
        toggled = !toggled;
    };
    /* sorting for remaining columns */
    $scope.sortBy = 'name';
    $scope.sortDescending = false;

    $scope.sort = function(column) {
        if ($scope.sortBy === column) {
            $scope.sortDescending = !$scope.sortDescending;
        } else {
            $scope.sortBy = column;
            $scope.sortDescending = false;
        }
    }

我在plunker网址中的方法是https://plnkr.co/edit/HPGnCIRNSdCFU6nI1eO2?p=preview

0 个答案:

没有答案