我需要使用ngTable来允许按列过滤。 在我的代码下面:
模板:
<table ng-table="tableParams" class="table" show-filter="true">
<tr ng-repeat="user in $data">
<td title="'Identifiant'" filter="{ login: 'text'}" sortable="'login'">
{{user.login}}</td>
<td>{{user.email}}</td>
</tr>
</table>
控制器:
angular.module('tessicommunicationApp')
.controller('UserManagementController', ['$scope', '$filter', 'Principal', 'User', 'ParseLinks', 'Language', 'NgTableParams', function ($scope, $filter, Principal, User, ParseLinks, Language, NgTableParams) {
//something before...
$scope.loadAll = function () {
User.query({
page : $scope.page - 1,
size : 20
}, function (result, headers) {
$scope.links = ParseLinks.parse(headers('link'));
$scope.totalItems = headers('X-Total-Count');
//$scope.users becomes an array of ressources
$scope.users = result;
});
};
//something again...
$scope.loadAll();
//something again...
$scope.tableParams = new NgTableParams({
page : 1, // show first page
count : 10, // count per page
sorting : {
name : 'asc' // initial sorting
}
}, {
total : 0,
getData : function ($defer, params) {
var filter = params.filter();
var sorting = params.sorting();
var count = params.count();
var page = params.page();
$defer.resolve($scope.users);
},
data : $scope.users
})
}
]);
可能有几个错误,但我已经尝试了很多东西......请告诉我合适的错误!