Angular JS ordering in the table does not change

0

I am making a call from the server to a user list, the result arrives quietly, but the sort order is not working.

HTML

<div class="table-responsive">
                <table class="table table-striped table-responsive">
                    <thead>
                        <tr>
                            <th><span id="orderColumn"  ng-click="changeSorting('id');sortType = 'id'; sortReverse = !sortReverse;">Registro <i ng-class="getIcon('id')" class="iSort halflings"></i></span></th>
                            <th><span ng-click="changeSorting('login');sortType = 'login'; sortReverse = !sortReverse">Usuário <i ng-class="getIcon('login')" class="iSort halflings"></i></span></th>
                            <th><span ng-click="changeSorting('name');sortType = 'name'; sortReverse = !sortReverse">Nome <i ng-class="getIcon('name')" class="iSort halflings"></i></span></th>
                            <th><span ng-click="changeSorting('surname');sortType = 'surname'; sortReverse = !sortReverse">Sobrenome <i ng-class="getIcon('surname')" class="iSort halflings"></i></span></th>                                
                            <th><span ng-click="changeSorting('occupation');sortType = 'occupation'; sortReverse = !sortReverse">Cargo <i ng-class="getIcon('occupation')" class="iSort halflings"></i></span></th>
                            <th><span ng-click="changeSorting('department');sortType = 'department'; sortReverse = !sortReverse">Departamento <i ng-class="getIcon('department')" class="iSort halflings"></i></span></th>
                            <th><span ng-click="changeSorting('sessionTimeout');sortType = 'sessionTimeout'; sortReverse = !sortReverse">Sessão <i ng-class="getIcon('sessionTime')" class="iSort halflings"></i></span></th>
                        </tr>
                    </thead>
                    <tbody>
                    <tr ng-repeat="roll in user2" ng-class="{'danger' : roll.info == 2, 'warning' : roll.info == 3}">
                            <td>{{roll.id}}</td>
                            <td>{{roll.login}}</td>
                            <td>{{roll.name}}</td>
                            <td>{{roll.surname}}</td>
                            <td>{{roll.occupation}}</td>
                            <td>{{roll.department}}</td>
                            <td>{{roll.sessionTimeout}}</td>
                            <td><span ng-click="alterarUsuario(roll.id)"><a href="#/usuario/cadastro"> Alterar</a></span></td>
                            <td><span ng-click="remover()"> Remover</span></td>
                        </tr>
                    </tbody>
                </table>

Angular

$scope.user2;   

$scope.consultar = function (callback) {
    console.log("entrou no consultar");
    var token = getCookie("token");
    var json = {};
    consumeService (token, JSON.stringify(json), "funcionario/getAllFuncionarios", "POST", "alerta", function(result){
        callback(result);
    });
};

$scope.chamar = function (){
    $scope.consultar(function(result){
        console.log("Query :"+ JSON.stringify(result));
        $scope.user2 = result;
    });
};



$scope.init = function () {
    console.log("ta entrando no init")
    $scope.chamar();
};

$scope.init();
$scope.sort = { active: '', descending: undefined}    


/**
 * Metodo que dispara a alteracao de ordenação
 * e seu respctivo icone
 */
$scope.changeSorting = function(column) {
  var sort = $scope.sort;
  if (sort.active == column) {
     sort.descending = !sort.descending;
  } 
  else {
    sort.active = column;
    sort.descending = false;
  }
};

/**
 * Metodo para alteracao de icone de Ordenação
 * a partir do estado que ela se encontra
 */
$scope.getIcon = function(column) {
  var sort = $scope.sort;
  if (sort.active == column) {
    return sort.descending
      ? 'halflings-sort-by-attributes-alt'
      : 'halflings-sort-by-attributes';
    }
  return 'halflings-sort';
}

Is there something wrong with the way I'm doing ?? I can not seem to find the problem.

    
asked by anonymous 08.12.2015 / 20:55

1 answer

2

The problem may lie in the fact that at no time is the sort object mentioned in ng-repeat , or applied to the collection.

Another factor - in no part of your code is the $scope.user2 collection mentioned, even though it is the data source of your ng-repeat .

    
08.12.2015 / 21:51