【问题标题】:Pagination gets "stuck"?分页“卡住”了?
【发布时间】:2014-07-23 04:02:35
【问题描述】:

我有一个简单的表格应用程序,它显示带有名称、数字、日期等列的虚拟数据。您可以按列对其进行排序,并且它是分页的。

但是,当我使用分页时,有些行会卡在顶部。它有点按我想要的列的字母顺序排序,但是当页面发生变化时(假装第 4 页),前几行 下面 的行会发生变化,而最上面的行不会改变。

Here is a functional plunker:

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


【解决方案1】:

startFrom:currentRow 移动到orderBy:sorting.predicate:sorting.reverse 之后。

您想在排序后过滤

【讨论】:

  • 简单的错误。感谢您的帮助!
【解决方案2】:

http://plnkr.co/edit/7BbgJ4TMU0pSY8gyDLef?p=preview

<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 |  orderBy:sorting.predicate:sorting.reverse | startFrom:currentRow | limitTo:itemsPerPage">
        <td ng-repeat="key in keys">
          {{row[key]}}
        </td>
      </tr>
    </table>

【讨论】:

  • 菲尔桑德勒领先你一分钟;)
  • 不到一分钟,生活很艰难:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-09-21
  • 2012-06-23
  • 2021-10-08
  • 2016-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多