【发布时间】:2014-07-23 04:02:35
【问题描述】:
我有一个简单的表格应用程序,它显示带有名称、数字、日期等列的虚拟数据。您可以按列对其进行排序,并且它是分页的。
但是,当我使用分页时,有些行会卡在顶部。它有点按我想要的列的字母顺序排序,但是当页面发生变化时(假装第 4 页),前几行 下面 的行会发生变化,而最上面的行不会改变。
HTML:
<pagination class="pagination pagination-sm" items-per-page="itemsPerPage" total-items="totalItems" ng-model="currentPage" ng-change="pageChanged()"></pagination>
<table class="table table-hover">
<tr>
<th ng-repeat="key in keys" ng-click="sorting.predicate=key;">
{{key}}
</th>
</tr>
<tr ng-repeat="row in data | startFrom:currentRow | orderBy:sorting.predicate:sorting.reverse | limitTo:itemsPerPage">
<td ng-repeat="key in keys">
{{row[key]}}
</td>
</tr>
</table>
角度:
app.filter('startFrom', function () {
return function (input, start) {
start = +start;
return input.slice(start);
};
});
$scope.data = [{
"id": 0,
"age": 30,
"name": "Trina Pace",
"gender": "female",
"email": "trinapace@darwinium.com",
"phone": "+1 (874) 414-2654"
},etc..];
$scope.keys = Object.keys($scope.data[0]);
$scope.totalItems = $scope.data.length;
$scope.itemsPerPage = 25;
$scope.currentPage = 1;
$scope.currentRow = 0;
$scope.pageChanged = function () {
$scope.currentRow = ($scope.currentPage - 1) * $scope.itemsPerPage;
console.log('current row: ' + $scope.currentRow);
console.log('items per page: ' + $scope.itemsPerPage);
};
$scope.sorting = {predicate:'name',reverse:false};
我是否错过了,和/或做错了什么?
【问题讨论】:
-
我给了所有空名称值,但仍然看到奇怪的行为。您确定您没有同时更改其他内容吗?
-
看来问题不在于空值。更新了我上面的问题。很好的收获。
标签: angularjs twitter-bootstrap pagination angularjs-ng-repeat angular-ui-bootstrap