简体   繁体   English

angularjs数据表无法重新初始化表错误

[英]angularjs Datatables Cannot Reinitialize Table Error

I am using angularjs Datatables and keep running into an error. 我正在使用angularjs数据表,并不断遇到错误。

DataTables Warning: table id=DataTables_Table_0 - Cannot reinitialise Datatable. DataTables警告:表ID = DataTables_Table_0-无法重新初始化Datatable。

I have two watches to run the report as the user changes input. 当用户更改输入时,我有两个手表来运行报告。

$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);
        });
    }

}

And in my template 在我的模板中

<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>

Can someone please shed some light onto what I am doing wrong here? 有人可以告诉我我在这里做错了什么吗?

The error was because you were trying to reinitialize an existing database. 该错误是因为您试图重新初始化现有数据库。 What you need to include is .withOption("destroy", true) to: 您需要包括的是.withOption("destroy", true)以:

$scope.dtOptions = DTOptionsBuilder.newOptions()

That will resolve the issue. 这样可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM