如何在angularJS中的第一行之后对div进行排序

时间:2015-07-15 06:45:56

标签: angularjs

我使用ng-repeat为记录创建基于div的布局,现在我希望在排序时不应该影响第一行。

Name Age Area
V    29    C
S    20    D
D    39    F
V    28    P

如果用户点击名称(排序应该同时发生asc和desc) 但是在第一排之后。

结果应该是

Name Age Area
V    29  C
D    39  F
S    20  D
V    28  P

我使用角度$ filter(' orderBy')进行排序

使用的代码:

<div class="heading row titleBar">
        <div class="col-md-3 col-sm-3 m-name tog" ng-click="reverse=!reverse;order('user.name', reverse);" data-predicate='name'><h4 class="name on" data-ng-bind="name"></h4></div>
        <div class="col-md-3 col-sm-3 t-name tog" ng-click="reverse=!reverse;order('user.title', reverse);" data-predicate='title'><h4 data-ng-bind="title"></h4></div>
        <div class="col-md-4 col-sm-4 s-name tog" ng-click="reverse=!reverse;order('user.userStatus', reverse);" data-predicate='userStatus'><h4 data-ng-bind="status"></h4></div>
</div>

<div class="profiler complete-profile animation_1" ng-class="{active:show}" id='{{$index}}' ng-repeat="memberList in recordField = (List.slice(0,pageSize))">

                    <div class="table-row clearfix">
                    /*code*/

                    </div>
                </div>

的js

$scope.order = function(predicate, reverse) {
        $scope.List = $filter('orderBy')($scope.List, predicate, reverse);
    };

是否可以设置任何配置来实现它。

2 个答案:

答案 0 :(得分:2)

执行此操作的一种方法是从数组中切割第一个项目,然后连接已过滤的切片数组的其余部分。

$scope.order = function(predicate, reverse) {
  $scope.List = $scope.List.slice(0, 1)
    .concat($filter('orderBy')($scope.List.slice(1), predicate, reverse));
};

答案 1 :(得分:0)

只需使用&#34; ng-if&#34;在div标签中。 $ index给出ng-repeat中的当前索引

<div class="profiler complete-profile animation_1" ng-class="{active:show}" id='{{$index}}' ng-repeat="memberList in recordField = (List.slice(0,pageSize))" ng-if="$index > 0">