jeudi 24 septembre 2015

angularjs checkbox toggleselection on pagination not working?

I have 2 pages of users, so when I check 2 check-boxes on page 1 and uncheck one of them, the toggleSelection() method is called. But if I navigate to page 2 and comeback to page 1 again and uncheck the checkbox the toggle selection is not being called.

Here is my code:

 <table id="UserInfoTable" class="table table-hover table-bordered table-responsive">
                <thead>
                    <tr style="background-color:black;color:white;border:none!important">
                        <th style="border:none!important" ng-show="canInviteOrEdit">Select</th>

                    </tr>
                </thead>
                <tbody>
                    <tr data-ng-repeat="subscription in groupDetail.membership| startFrom:currentPage*pageSize | limitTo:pageSize" class="rowbottom-color" ng-class-odd="'odd'" ng-class-even="'even'" style="border:none!important">
                        <td ng-show="canInviteOrEdit" style="border:none!important">
                            <input id="{{subscription.MembershipId}}" type="checkbox" value="{{subscription.MembershipId}}" ng-model="chckedIndexs" ng-checked="chckedIndexs.indexOf(subscription.MembershipId) > -1" ng-change="checkedIndex(subscription.MembershipId)" />

                        </td>
                    </tr>
                </tbody>
            </table>
            <ul class="page-button text-center clearfix mbz" ng-show="groupDetail.membership.length > pageSize">
                <li data-ng-repeat="t in getPagination(groupDetail.membership)">
                    <span data-ng-class="{disabled: currentPage == $index}" data-ng-disabled="currentPage == $index" data-ng-click="getCurrentPage($index)">
                    </span>
                </li>
            </ul>

 $scope.chckedIndexs = [];

        $scope.checkedIndex = function (student) {
            if ($scope.chckedIndexs.indexOf(student) === -1) {
                $scope.chckedIndexs.push(student);
            }
            else {
                $scope.chckedIndexs.splice($scope.chckedIndexs.indexOf(student), 1);
            }
        }

   $scope.getCurrentPage = function (n) {
            $scope.currentPage = n;
        };

        $scope.getPagination = function (membership) {
            if (membership) {
                var numPages = Math.ceil(membership.length / $scope.pageSize);
                var pages = [];

                for (var i = 0; i < numPages; i++) {
                    pages[i] = i;
                }

                return pages;
            }
        };

Any suggestions would be helpful.




Aucun commentaire:

Enregistrer un commentaire