angularjs - 智能表分页不适用于服务器端过滤

标签 angularjs smart-table

我有一个正在使用 AngularJS 处理的智能表。该表使用自定义管道来搜索和排序其数据。我还要求表格具有工作分页以及一个下拉框,以便您可以选择要显示的行数(想想数据表)。

对于搜索和排序,自定义管道可以毫无问题地触发我的 ajax 请求。但是,当我单击任何页码或更改要显示的行数时,管道不会被触发。

页码似乎设置为调用 setPage(page) (这是由 st-pagination 指令设置的)但没有任何 react - 并且没有引发错误。

如何在更改显示的行数或在分页控件中单击页面 # 时触发自定义管道?

这是我的 HTML:

<table class="table table-striped table-bordered" st-table="leadsCollection" st-safe-src="leads" st-pipe="serverFilter">
...
<tbody>
   <tr data-toggle="modal" data-target="#modal-source" ng-repeat="source in leadsCollection" ng-click="rowClick($index);">
      <td>{{source.leaddate}}</td>
      <td>{{(source.distance > 100) ? 'Long Distance' : 'Local'}}</td>
      <td>{{source.origin_city}}, {{source.origin_state}}</td>
      <td>{{source.destination_city}}, {{source.destination_state}}</td>
      <td>{{source.est_move_date}}</td>
      <td>{{source.distance}} mi</td>
      <td>{{source.number_bedrooms}} br</td>
      <td></td>
   </tr>
</tbody>
<tfoot>
  <tr>
     <td colspan="8">
        <div class="form-group col-md-1">
            <label>Show:</label> <select class="form-control" ng-model="itemsByPage"><option value="10">10</option><option value="25">25</option><option value="50">50</option><option value="100">100</option></select>
        </div>
        <div class="pull-right" st-pagination="" st-items-by-page="itemsByPage"></div>
     </td>
  </tr>
</tfoot>
</table>

这是 Controller :
.controller('Leads', function ($scope, $http) {
$scope.leads = [];
$scope.leadsCollection = [].concat($scope.leads);
$scope.itemsByPage = "10";

$scope.rowClick = function (idx)
{
    $scope.editor = $scope.leads[idx];
}

$scope.serverFilter = function(tablestate)
{
    $http.post("/portal/api/loadleads",tablestate).success(function(response){
        console.log(response);
        $scope.leads = response;
        $scope.leadsCollection = [].concat($scope.leads);
    });
}

})

最佳答案

为了让智能表触发过滤器,您必须设置数据加载的页数。要使上述过滤器正常工作,只需添加:

tablestate.pagination.numberOfPages = response.totalPages;

Smart Tables 似乎需要设置它才能正确绑定(bind)事件。

关于angularjs - 智能表分页不适用于服务器端过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28647865/

相关文章:

javascript - 从 Angular 范围值动态更改分页页面大小

HTML CSS,表格 TH 和 TD 不在同一行

javascript - 智能表格无法正确排序

javascript - 路由更改后,运行一次js脚本

javascript - jQuery 多选不适用于 AngularJS

angularjs - Angular-JWT header 中没有标记

javascript - angularjs 智能表以编程方式排序

angularjs - 清除特定 View 的 $stateParams

angularjs - ionic 1 应用程序中的实现动态链接插件无法运行

javascript - 表中的 Angular ng-repeat 用数组迭代键