清除表行分页上的css类

时间:2015-07-07 09:51:10

标签: angularjs pagination smart-table

我有一张带有分页的智能桌子。我有一个控制器,将css类应用于所选行。所以问题在于它将选择保留在其他页面上的索引中,所以我在搜索时使用或点击分页来清除类。

这是表格:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="TestCtrl">
<div class="smart-table-container">
                <table id="mytable" st-safe-src="dataSet" st-table="displayed" class="smart-table table">
                    <thead>
                    <tr >
                        <th >A COLUMN</th>
                        <th >A COLUMN</th>
                        <th >A COLUMN</th>
                        <th >A COLUMN</th>
                        <th >A COLUMN</th>
                    </tr>
                </thead>

                <tbody data-ng-dblclick="scrollTo()">

                    <tr data-ng-repeat="row in displayed" st-select-row="row" st-select-mode="single" data-ng-click="$parent.setClickedRow($index)" and data-ng-class="{'selected':$index == $parent.selectedRow}">
                        <td data-ng-click="$parent.selData(row);">{{$index}}</td>
                        <td data-ng-click="$parent.selData(row);">{{row.asd}}</td>
                        <td data-ng-click="$parent.selData(row);">{{row.dsa}}</td>
                        <td data-ng-click="$parent.selData(row);">{{row.qwe}}</td>
                        <td data-ng-click="$parent.selData(row);">{{row.ewq}}</td>
                    </tr>
                </tbody>
                    <tfoot>
                        <tr>
                                <td class="text-center" st-pagination="" st-items-by-page="5" colspan="8">
                                </td>
                        </tr>
                    </tfoot>
                </table>
            </div>
       </div>

这是与选择相关的代码:

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

function TestCtrl($scope) {
    $scope.selectedRow = null;
    $scope.displayed = [{asd:3},{asd:3},{asd:3},{asd:3},{asd:3},{asd:3}]
    $scope.setClickedRow = function(index){
         $scope.selectedRow = index;
    }
}

和css类:

.selected {
    background-color: #67BBED;
}

1 个答案:

答案 0 :(得分:0)

将此包含在您的控制器中可能有效

$scope.$watch('displayed', function() {
    $scope.selectedRow = null;
});

http://plnkr.co/edit/hX093vHZkoZSPvfRnqJE?p=preview