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

时间:2016-05-17 15:05:47

标签: javascript angularjs sorting

嘿大家正在尝试对我的所有记录进行排序,当我使用排序键和功能时只在当前页面上进行排序我没有理解它为什么它只在当前页面中排序& #39;我的代码:

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

ᐧ感谢您的帮助

1 个答案:

答案 0 :(得分:1)

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

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

其中$ scope.users是你重复的,cin是你的排序标准 希望这有帮助!