0
使用jQuery datatables library,我能夠實現數據表。在我的控制器中,我已初始化數據表。表格用戶界面工作正常。但是,當我從我的API獲取新數據時,我的數據顯示在表格的下方,而不是在數據表中顯示。這是因爲datatable不重新加載。我試圖重新加載數據表,但沒有運氣,它不適用於我。jquery datatables重新加載角度的數據
控制器
// When the search button clicked
$scope.search = function(){
var newData = [{..}];
$scope.news = newData;
}
// Datatable init
jQuery('.js-dataTable-simple').dataTable({
columnDefs: [ { orderable: false, targets: [ 4 ] } ],
pageLength: 10,
lengthMenu: [[5, 10, 15, 20], [5, 10, 15, 20]],
searching: false,
oLanguage: {
sLengthMenu: ""
},
dom:
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-6'i><'col-sm-6'p>>"
});
HTML
<table class="table table-bordered table-striped js-dataTable-simple">
<thead>
<tr>
<th class="text-center"></th>
<th>Title</th>
<th class="hidden-xs">Source</th>
<th style="width: 15%;" class="hidden-xs">Date</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="n in news" ng-show="isSearch == true">
<td class="text-center">{{ $index }}</td>
<td class="font-w600">{{ n.title }}</td>
<td class="hidden-xs">{{ n.source }}</td>
<td class="hidden-xs">{{ n.selected_date | date: 'MMM d, y h:mm a' }}</td>
</tr>
</tbody>
</table>