2017-09-28 1 views
0

で働いていません。.withColVisは()angularjs

このplunkerを確認してください。 plunkr link

私は、それが働いている.withDOM()を使用している場合。 チェックこのplunker.

は、私はまた、公式サイトcheck this linkからの参照を取る:この問題を解決するために私を助け

、私は自分のアプリケーションで.withColVis()を使用したいです。

.withColVis()は、列のリストを表示するために使用されます。

.withColVis()および.withDOM('<"H"Cr>t<"F"ip>')は、同じ機能を実行します。たとえば、Show/Hide columnオプションを表示します。しかし.WithDOM()が動作しており、.withColVis()が機能していません。

(function(angular) { 
    'use strict'; 
    angular.module('datatablesSampleApp', ['datatables']). 
    controller('simpleCtrl', 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') 
    ]; 
    }); 
})(angular); 

ワーキングコード::コード動作しない

(function(angular) { 
    'use strict'; 

    angular.module('datatablesSampleApp', ['datatables']) 
    .controller('SimpleCtrl', SimpleCtrl); 

    function SimpleCtrl(DTOptionsBuilder, DTColumnBuilder) { 
    var vm = this; 
    vm.dtOptions = DTOptionsBuilder.newOptions() 
     .withOption('sAjaxSource', 'data.json') 
     .withDataProp('data') 
     .withDOM('<"H"Cr>t<"F"ip>') 
     .withPaginationType('full_numbers') 
     .withDisplayLength(10); 
    vm.dtColumns = [ 
     DTColumnBuilder.newColumn('id', 'ID'), 
     DTColumnBuilder.newColumn('firstName', 'First name'), 
     DTColumnBuilder.newColumn('lastName', 'Last name') 
    ]; 

    } 
})(angular); 

答えて

1

をあなたここフォークplnkrから、仕事をする(現在は非推奨)ColVisプラグインを取得するためにangular-datatables.colvis.jsを含める必要があります:

<script src="https://rawgithub.com/l-lin/angular-datatables/v0.6.2/dist/plugins/colvis/angular-datatables.colvis.js"></script> 

datatables.colvisモジュールを挿入:

angular.module('datatablesSampleApp', ['datatables', 'datatables.colvis']). 

https://plnkr.co/edit/edZcE3DLjaDSuNhTu2MV?p=preview

+0

はあなたの助けをとても感謝 –

+0

列の可視性の状態を保存することは可能でしょうか?ユーザーがそのページに再度アクセスしたときに再びその状態を表示しますか? –

+0

@chiragsataparaは、私はあなたが '.withColVis'(これは廃止され、AD自分と一緒にそれを使用したことがありません)を使用する場合は知らないが、私は**ボタンと' colvis' **と '.withOption(「stateSave」を使用する場合、true) '表示/非表示の列は自動的に"記憶 "され、ローカルマシンのlocalstorageに格納されます。私はどこでもAD、複数のプロジェクトを使用しているので、擁護しています。 – davidkonrad