2015-09-27 50 views
0

我試圖實現ngtable,以便擁有開箱即用的過濾器和分頁功能,但它看起來並不像他們說的那樣容易實現。ngtable filters not working

我的數據在表中正確加載,但實際的過濾器根本沒有響應。下面是MyCtrl在我的桌子代碼:

<table ng-table="tableParams" class="table table-condensed table-bordered table-striped"> 
     <tr ng-repeat="movie in items.movies"> 
      <td data-title="'Title'" filter="{ title: 'text'}" sortable="'title'">{{movie.title}}</td> 
      <td data-title="'Duration'" filter="{duration: 'number'}" sortable="'duration'">{{movie.duration | durationFilter | date:'HH:mm:ss'}} hrs</td> 
     </tr> 
    </table> 

在我所服務的數據工廠到控制器然後觸發NG表app.js:

app.controller('MyCtrl', function($scope, itemsFactory){ 

itemsFactory.getItems().success(function(data){ 
      $scope.items = data; 
      tableParams = new NgTableParams({}, { data: data}); 
     }); 

}); 

的結果是,所有的數據都顯示而內容上方的輸入過濾器則不起作用。有什麼我失蹤?

回答

1

假設您的HTML包含類似<table ng-table="tableParams"的東西,您希望將新的NgTableParams指定爲$scope.tableParams,以便表格可以看到它們。目前您正在分配一個局部變量。

另外,通過「use strict」啓用Javascript嚴格模式。避免這樣的錯誤。

-1

嘗試你的代碼

<tr ng-repeat="movie in items.movies"> 

改變

<tr ng-repeat="movie in $data"> 
+0

試試這個去的意見,而不是答案。你不確定這會解決問題。 – Nic3500