2014-12-05 69 views
3

我正在使用AngularJS與Angular-datatables(http://l-lin.github.io/angular-datatables/),我正在使用數據表ColVis插件。表呈現細但排序列標題或使用ColVis顯示/隱藏欄刪除所有數據:角度數據表與ColVis,排序或隱藏列刪除所有數據

我有一個角控制器

<div ng-controller="withColVisCtrl"> 
<table datatable dt-options="dtOptions"> 
    <thead> 
    <tr> 
     <th>Col 1</th> 
     <th>Col 2</th>   
    </tr> 
    </thead> 
    <tbody> 
    <tr ng-repeat="value in value_list"> 
     <td>col 1 data</td> 
     <td> col 2 data</td> 
    </tr> 
</tbody> 
</table> 

withColVisCtrl內的表使用,所述控制器:

angular.module('myApp').controller('withColVisCtrl', function ($scope, DTOptionsBuilder) { 
     $scope.dtOptions = DTOptionsBuilder.newOptions() 
      .withBootstrap() 
      .withColVis() 
      .withDOM('C<"clear">lfrtip')             
      .withColVisOption('aiExclude', [1]);          
     }); 

當我點擊列標題或使用ColVis顯示/隱藏時,表似乎重繪但沒有數據。我的數據通過API傳遞,因此它與Angular-Datatables ColVis示例(http://l-lin.github.io/angular-datatables/#/withColVis)不同。

我在這裏錯過了什麼?

回答

3

沒有出現的原因是因爲您需要數據源。所提供的示例有以下代碼:

angular.module('datatablesSampleApp', ['datatables']).controller('withColVisCtrl', function ($scope, DTOptionsBuilder, DTColumnBuilder) { 
    $scope.dtOptions = DTOptionsBuilder.fromSource('data.json') 
     .withPaginationType('full_numbers') 
     // Active ColVis plugin 
     .withColVis() 
     // Add a state change function 
     .withColVisStateChange(function(iColumn, bVisible) { 
      console.log('The column' + iColumn + ' has changed its status to ' + bVisible) 
      }) 
     // Exclude the last column from the list 
     .withColVisOption('aiExclude', [2]); 
    $scope.dtColumns = [ 
     DTColumnBuilder.newColumn('id').withTitle('ID'), 
     DTColumnBuilder.newColumn('firstName').withTitle('First name'), 
     DTColumnBuilder.newColumn('lastName').withTitle('Last name') 
    ]; 
}); 

通知的第二行:$scope.dtOptions = DTOptionsBuilder.fromSource('data.json')

正在使用的方法是在數據從一個JSON文件拉動。

查看網絡時,這是他們的數據源的外觀 - http://l-lin.github.io/angular-datatables/data.json?_=1417925914539

只需重新創建該數據文件,使用DTOptionsBuilder.fromSource(PATH_TO_FILE)加載數據文件,那麼您應該很好。

讓我知道你是否有任何問題。

0

@Dom,

請看截圖,這裏的方法,工作正常,但調用來自用新數據UI不會得到改變,或者如果我使用$手動申請調用API第二成功響應這種方法時那麼數據表開始表現怪異。

請糾正我,如果我做錯了什麼

enter image description here