0
I’m making a call from the server to a list of users, the result comes smoothly, but the ordering 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';
}
There’s something wrong with the way I’m doing ?? I’m not finding the problem.
I updated the post here, calling the users for a service I did, I am able to bring them quietly, only the ordering does not work
– Victor Siqueira
@Victorsiqueira A functional ordering mechanism can be seen in this post: http://stackoverflow.com/a/18186947/1845714
– OnoSendai