从角度范围值动态更改分页页面大小

时间:2016-04-20 13:09:19

标签: javascript html angularjs pagination smart-table

我试图允许用户更改要显示的表中的行数。 Web应用程序用于所有类型的设备,因此用户需要能够选择要显示的行数以最小化滚动。

这是javascript模型

$scope.pageSizes = [
  { size: 10},
  { size: 25, isSelected: true },
  { size: 50}
];

HTML代码。这是我的页面大小选择器。

<li ng-repeat="pageSize in pageSizes">
  <a href="javascript:void(0)" ng-click="changePageSize(pageSize.size)"><span ng-class="{ orange: pageSize.isSelected }">{{pageSize.size}}</span></a>
</li>

该表位于同一HTML文件中。

<table st-table="users" st-safe-src="safeUsers" class="table-striped argus-table">
  <thead>
    <tr>
      <th st-sort="id" class="sortable min-width">Id</th>
      <th st-sort="username" class="sortable">Username</th>
      <th st-sort="email" class="sortable">Email</th>
      <th class="table-action-header"></th>
      <th class="table-action-header"></th>
      <th class="table-action-header"></th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="user in users">
      <td>ID</td>
      <td>Username</td>
      <td>Email</td>
      <td>Option 1</td>
      <td>Option 2</td>
      <td>Option 3</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td class="text-center" st-pagination="" st-items-by-page="25" colspan="6"></td>
    </tr>
  </tfoot>
</table>
  

st-items-by-page="25"我相信我必须放置我的角度代码。

我尝试使用范围功能查找新选择的

$scope.changePageSize = function (pageSize) {
  $scope.filter.pageSize = pageSize;

  _.find($scope.pageSizes, function (page) {
    if (page === pageSize) {
      $scope.selectedPageSize = page.size;
      page.isSelected = true;
    }
    else
      page.isSelected = false;
  });
};

再次页脚

<tfoot>
  <tr>
    <td class="text-center" st-pagination="" st-items-by-page="{{selectedPageSize}}" colspan="6"></td>
  </tr>
</tfoot>

然而,这会导致错误

  

Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 2 of the expression [{{getSelectedPageSize}}] starting at [{getSelectedPageSize}}].

任何帮助将不胜感激。感谢

1 个答案:

答案 0 :(得分:2)

不要使用模板表示法({{scopeValue}})为每页提供项目,只需提供一个表达式,该表达式已解析为$scope

上的值

这个

st-items-by-page="{{selectedPageSize}}"

应该是这样的

st-items-by-page="selectedPageSize"

docs

中有一个例子