AngularJs对所有页面中的所有记录进行排序

AngularJs Sorting all records across all pages

本文关键字:记录 排序 AngularJs      更新时间:2023-09-26

嘿,当我使用排序键和函数时,每个人都在试图对我的所有记录进行排序。我只在当前页面上进行排序,但我没有得到它为什么它只在当前页上进行排序?以下是我的代码:

 <table class="table table-bordered table-hover table-striped">
                    <thead>
                        <tr>
                            <th ng-click="sort('cin')">Cin <span
                                class="glyphicon sort-icon" ng-show="sortKey=='cin'"
                                ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
                            </th>
                            <th ng-click="sort('nom')">Nom <span
                                class="glyphicon sort-icon" ng-show="sortKey=='nom'"
                                ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
                            </th>
                            <th ng-click="sort('prenom')">Prenom <span
                                class="glyphicon sort-icon" ng-show="sortKey=='prenom'"
                                ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
                            </th>
                            <th ng-click="sort('email')">Email <span
                                class="glyphicon sort-icon" ng-show="sortKey=='email'"
                                ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
                            </th>
                            <th ng-click="sort('adresse')">Adresse <span
                                class="glyphicon sort-icon" ng-show="sortKey=='adresse'"
                                ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
                            </th>
                            <th>index</th>
                            <th ng-click="sort('role_name')">Roles <span
                                class="glyphicon sort-icon" ng-show="sortKey=='adresse'"
                                ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr
                            dir-paginate="user in users|orderBy:sortKey:reverse|filter:search|itemsPerPage:5">
                            <td>{{user.cin}}</td>
                            <td>{{user.nom}}</td>
                            <td>{{user.prenom}}</td>
                            <td>{{user.email}}</td>
                            <td>{{user.adresse}}</td>
                            <td>{{$index}}</td>
                            <td><table>
                                    <tr ng-repeat=" role in user.roles">
                                        <td>{{role.role_name}}</td>
                                    </tr>
                                </table></td>
                            <td>
                                <button ng-click="edit(user)" class="btn btn-warning btnt"
                                    data-toggle="modal" data-target="#myModal">
                                    <i class="glyphicon glyphicon-pencil"></i>
                                </button>
                            </td>
                            <td><button ng-click="supp(user.cin)"
                                    class="btn btn-danger btnt">
                                    <i class="glyphicon glyphicon-remove"></i>
                                </button></td>
                        </tr>
                    </tbody>
                </table>

这是我的js代码:

$scope.sort = function(keyname){
        $scope.sortKey = keyname;   // set the sortKey to the param passed
        console.log("keyname="+$scope.keyname);
        $scope.reverse = !$scope.reverse; // if true make it false and
                                            // vice versa
    }

ᐧ感谢任何帮助

您可以尝试的一件事是在控制器本身中对结果进行排序

$filter('orderBy')($scope.users, 'cin');

其中$scope.users是您要重复的内容,cin是您的排序标准。
希望得到帮助!