Noble
Noble

Reputation: 115

Clear css class on table row pagination

I got a smart-table with pagination. I have a controller that apply a css class to the selected row. So the issue is that it keeps the selection on the index on other pages, so I'm searching for a way to clear the class when I use or click pagination.

This is the table:

<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>

And this is the code related to the selection:

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;
    }
}

And the css class:

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

Upvotes: 0

Views: 648

Answers (1)

Aumit
Aumit

Reputation: 53

Including this in your controller may work

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

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

Upvotes: 0

Related Questions