このexampleの2番目の答えを使用して、Angularjsフレームワークを使用してDatatable jQueryを作成しようとしています。 ng-repeatがテーブルをロードするとすぐに、DataTable()を初期化します。AngularjsでDatatableを使用しているエラー
矢印、フィルタ、検索バーが表示されますが、何らかの理由で矢印をクリックしてもソートされません。彼らは上下に切り替えますが、並べ替えはしません。検索ボックスでは、行の実際の値を検索するときにヘッダー名で検索します。
ボタンがクリックされ、HTTP応答が受信されると、テーブルの "itms"に値が設定されるため、テーブル全体がレンダリングされるまで.DataTable()は呼び出されません。
私はまた、itmsがハードコードされていて、完全に動作するテーブルだけでテストしました。私は何が欠けていますか?
JS:
angular.module('abcapp')
.directive('repeatDone', function() {
return function(scope, element, attrs) {
if (scope.$last) { // all are rendered
$('#my-table').DataTable();
}
}
})
HTML:
<div ng-if="itms && itms.length > 0" class="row">
<table id="my-table" class="table table-striped" cellspacing="0" width="100%">
<thead>
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
<th>d</th>
</tr>
</thead>
<tfoot>
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
<th>d</th>
</tr>
</tfoot>
<tbody>
<tr ng-repeat="itm in itms track by $index" repeat-done>
<td>{{itm.a}}</td>
<td>{{itm.b}}</td>
<td>{{itm.c}}</td>
<td>{{itm.d}}</td>
</tr>
</tbody>
</table>
</div>
はちょうどFYI、すでにこのために設計されて完全に肉付けライブラリが存在し、[角度-のDataTable](http://l-lin.github.io/angular-datatables/#/welcome) 。 – Claies