2016-06-01 4 views
0

以下の機能が同じ角度コントローラにあります。角度を使用してjquery datatable行のチェックボックスをバインドする方法

$ scope.init()は、Jqueryデータテーブルを構成するために使用します。最初の列に

Iはチェックボックスがあると私はチェックボックス変更/トグルにtoggleSelection()を呼び出し、オブジェクトIDを渡す必要があります。

しかし、私はそうすることができません。

$scope.init = function { 
var testTable = $('#testTable').dataTable($.extend({ 
    aaSorting:[[5, 'desc']], 
    fnRowCallback: function (nRow, object, iDisplayIndex){ 
      //some code to format rows 
    }, 
    aoColumns: [{ 
       mData: "id", sTitle: "", bSortable: false, 
       mRender:function(data, type, question){ 
       return '<input type="checkbox" ng-click="toggleSelection(' + object.id + ')"/>'; 
    }}, 
    //....Other columns 
    ], 
    fnServerData: TestApiHandler 
    }, defaultTableSettings)) 

    //TestApiHandler: Already configured for Ajax call 
    //defaultTableSettings: dafault setting for datatable 
} 

$scope.toggleSelection = function(id) { 
    console.log('Object Id' + id) 
} 

以下は、datatable用のHTMLです。

<table id="testTable" class="table table-bordered table-condensed table-striped table-hover "></table> 

答えて

0

使用以上の角度の方法:あなたのHTML内

<table...> <input ng-repeat="chbx in checkboxes" type="checkbox" ng-click="toggleSelection({{chbx .id}})"/> ... </table>

とコントローラで:

$scope.checkboxes = [{id: 42}, ...];

0

あなたはチェックボックスでngModelを使用することができます。お使いのコントローラで

<input ng-model="checkboxes[object.id]" ng-click=... /> 

$scope.checkboxes = []; 
+0

これが機能していません。私はまだ$ scope.checkboxesに空の配列を取得しています。 – Vivek

関連する問題