2014-12-05 70 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