我做了一个表格来显示数组中的值,我添加了一个过滤器。该表格分页最多每页5条记录。过滤器没有按预期显示
当我应用过滤器时会出现问题。例如,如果您搜索术语“ora”,将会有三个记录,每个页面上一个记录。
这些结果如何一起显示(在一页上,或它需要多少页,但没有消散),以及当我删除过滤器以显示它正常(在所有页面中)?
活代码可以在这里找到:https://plnkr.co/edit/QIcmQUqABDJcV3H6vqRo?p=preview
HTML:
<body ng-app="salariesApp" ng-controller="mainCtrl">
<table class="table">
<thead>
<tr>
<th ng-click="sortBy(id)">Nr. crt.</th>
<th ng-click="sortBy(an)">Anul</th>
<th ng-click="sortBy('den')">Denumirea institutiei/companiei</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableSearch"></td>
<td class="tableSearch"><input class="form-control" type="text" id="inputYear" ng-model="searchSal.an" ng-value={{crrYear}} /></td>
<td class="tableSearch"><input class="form-control" type="text" id="inputName" ng-model="searchSal.den" /></td>
</tr>
<tr ng-repeat="rows in showSal | filter: searchSal | orderBy: sortProperty: !reverse | filter : paginate track by $index">
<td class="spa-col-md-1">{{rows.id}}</td>
<td class="spa-col-md-2">{{rows.an}}</td>
<td class="col-md-5">{{rows.den}}</td>
</tr>
</tbody>
</table>
<pagination total-items="totalItems" ng-model="currentPage" max-size="5" boundary-links="true"
items-per-page="numPerPage" class="pagination-sm">
</pagination>
</body>
JS:
var app = angular.module("salariesApp", ['ui.bootstrap']);
app.constant("appConst", {
pagesLimit: 5,
crrYear: 2016
});
app.controller('mainCtrl', ['$scope', 'appConst', function($scope, appConst) {
$scope.crrYear = appConst.crrYear;
$scope.pageNum = {
linkBtnClass: 'linkBtnClass cursor-pointer'
};
$scope.showSal = [
{ id: '1', an: '2016', den: 'Oracle Romania' },
{ id: '2', an: '2016', den: 'Microsoft' },
{ id: '3', an: '2016', den: 'Computer Generated Solutions - CGS Europe' },
{ id: '4', an: '2016', den: 'IBM' },
{ id: '5', an: '2016', den: 'Luxoft' },
{ id: '6', an: '2016', den: 'Oracle Romania' },
{ id: '7', an: '2016', den: 'Luxoft' },
{ id: '8', an: '2016', den: 'Computer Generated Solutions - CGS Europe' },
{ id: '9', an: '2016', den: 'IBM' },
{ id: '10', an: '2016', den: 'Luxoft' },
{ id: '11', an: '2016', den: 'Oracle Romania' },
{ id: '12', an: '2016', den: 'Microsoft' },
{ id: '13', an: '2016', den: 'IBM' },
{ id: '14', an: '2016', den: 'Luxoft' }
];
$scope.searchSal = '';
$scope.sortProperty = $scope.showSal.id;
$scope.reverse = true;
$scope.sortBy = function (sortProperty) {
$scope.reverse = ($scope.sortProperty === sortProperty) ? !$scope.reverse : false;
$scope.sortProperty = sortProperty;
};
// PAGINATION:
$scope.totalItems = $scope.showSal.length;
$scope.currentPage = 1;
$scope.numPerPage = 5;
$scope.paginate = function(value) {
var begin, end, index;
begin = ($scope.currentPage - 1) * $scope.numPerPage;
end = begin + $scope.numPerPage;
index = $scope.showSal.indexOf(value);
return (begin <= index && index < end);
};
$scope.getOptionsClass = function (index) {
if (index > 0) {
return 'thumbnail nav-option-r';
} else {
return 'thumbnail nav-option-l';
}
};
}]);
你的调度器坏了。 – Lex