【发布时间】:2017-06-24 06:09:47
【问题描述】:
使用jQuery datatables library,我能够实现数据表。在我的控制器中,我已经初始化了数据表。表格 UI 工作正常。但是当我从我的 API 获取新数据时,我的数据显示在表格下方,使用 ng-repeat 而不是显示在数据表中。这是因为数据表没有重新加载。我曾尝试重新加载数据表,但没有运气,它对我不起作用。
控制器
// 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>
【问题讨论】:
标签: javascript jquery angularjs datatable