我正在使用angularjs Datatables并继续遇到错误。
DataTables警告:table id = DataTables_Table_0 - 无法重新初始化数据表。
当用户更改输入时,我有两只手表来运行报告。
$scope.dtInstance = {};
$scope.dtOptions = DTOptionsBuilder.newOptions().withPaginationType('full_numbers')
.withOption('responsive', true)
.withOption("autoWidth", false)
.withDOM('lfrtBip')
.withButtons(['copy', 'print', 'pdf', 'csv', 'excel']);
$scope.dtColumns = [
DTColumnBuilder.newColumn('display_name').withTitle('Name'),
DTColumnBuilder.newColumn('state_desc').withTitle('State'),
DTColumnBuilder.newColumn('state_Type').withTitle('State Type'),
DTColumnBuilder.newColumn('adjustedClientStartState').withTitle('State Start Date'),
DTColumnBuilder.newColumn('adjustedClientEndState').withTitle('State End Date'),
DTColumnBuilder.newColumn('timeInStateSeconds').withTitle('Seconds'),
DTColumnBuilder.newColumn('timeInStateMinutes').withTitle('Minutes'),
DTColumnBuilder.newColumn('timeInStateHour').withTitle('Hours'),
];
$scope.$watch('hours', function (newVal, oldVal)
{
if (!newVal) return;
runReport($scope.selectedClient.id, newVal);
});
$scope.$watch('selectedClient', function (newVal, oldVal)
{
if (!newVal) return;
runReport(newVal.id, $scope.hours);
});
var runReport = function (clientId, hours)
{
if (clientId != 'undefined' && clientId != undefined)
{
ubernurseService.ClientStateHistory(clientId, hours).then(function (results)
{
$scope.states = results.data;
if (results.data.length > 0)
{
$scope.notVisible = false;
}
else
{
$scope.notVisible = true;
}
}, function (error)
{
//alert(error.data.message);
});
}
}
在我的模板中
<div class="row">
<div class="col-md-10 col-md-offset-1">
<table datatable="ng" dt-options="dtOptions" dt-columns="dtColumns" dt-instance="dtInstance" class="table table-hover table-striped">
<thead>
<tr>
<th>Name</th>
<th>State</th>
<th>State Type</th>
<th>State Start Date</th>
<th>State End Date</th>
<th>Seconds</th>
<th>Minutes</th>
<th>Hours</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="state in states">
<td>{{state.display_name}}</td>
<td>{{state.state_desc}}</td>
<td>{{state.state_Type}}</td>
<td>{{state.adjustedClientStartState | date:'medium'}}</td>
<td>{{state.adjustedClientEndState | date:'medium'}}</td>
<td>{{state.timeInStateSeconds}}</td>
<td>{{state.timeInStateMinutes}}</td>
<td>{{state.timeInStateHour}}</td>
</tr>
</tbody>
</table>
</div>
</div>
有人可以对我在这里做错了吗?
答案 0 :(得分:0)
错误是因为您尝试重新初始化现有数据库。您需要包含的内容是.withOption("destroy", true)
:
$scope.dtOptions = DTOptionsBuilder.newOptions()
这将解决问题。