分页和过滤在angularjs中不稳定

时间:2016-03-02 10:24:47

标签: javascript html angularjs filtering ngtable

我有一个动态表,显示来自用户数组的数据。我想根据所有字段进行过滤,它们不是特定的,它们依赖于用户数组。用户数组也可以改变。



 $scope.usersTable = new ngTableParams({
   page: 1,
   count: 10
 }, {
   total: $scope.users.length,
   getData: function($defer, params) {
     debugger;

     $scope.data = params.sorting() ? $filter('orderBy')($scope.users, params.orderBy()) : $scope.users;
     $scope.data = params.filter() ? $filter('filter')($scope.users, params.filter()) : $scope.users; // in there this data must be filtered but it is not
     params.total($scope.data.length);

     $scope.data = $scope.data.slice((params.page() - 1) * params.count(), params.page() * params.count());
     $defer.resolve($scope.data);
   }
 });
 $scope.cols = Object.keys($scope.users[0]);

<input type="text" class="form-control" id="src_product " placeholder="Aramak İstediğiniz Ürün Alanını Giriniz" ng-model="src_product" ng-change="getProducts()">

<table ng-table="usersTable" id="productTable" class="table table-striped" show-filter="true">

  <tr>
    <th class=" bg-aqua-gradient  text-center" ng-repeat="column in cols">{{column}}</th>
    <th class="bg-aqua-gradient ">Adet</th>
  </tr>

  <tbody ng-form="labelPrintTableForm">
    <tr ng-repeat="row in data  | filter: src_product">

      <td class="highlighted" id="{{row.id}}_{{column}}" ng-class="{'unhighlighted':unselectedCells.indexOf(row.id + '_' + column) != -1}" ng-repeat="column in cols" onclick=" selectcells(this)">
        {{row[column]}}
      </td>
      <td class="highlighted">
        <input class=" input-group-sm " type="number" style="width: 100%; height: 30px !important" name=" adet" value="0" ng-minlength="0" required>
        <span ng-show="labelPrintTableForm.adet.$error.required">Adet alanı En az 0 olar</span>
      </td>


    </tr>
  </tbody>

</table>
&#13;
&#13;
&#13;

这不是在做过滤。我做错了什么?

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。我写了

$scope.data = params.filter() ? $filter('filter')($scope.users, params.filter()) : $scope.users; 

而不是

{{1}}