簡體   English   中英

angularjs數據表無法重新初始化表錯誤

[英]angularjs Datatables Cannot Reinitialize Table Error

我正在使用angularjs數據表,並不斷遇到錯誤。

DataTables警告:表ID = DataTables_Table_0-無法重新初始化Datatable。

當用戶更改輸入時,我有兩個手表來運行報告。

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

有人可以告訴我我在這里做錯了什么嗎?

該錯誤是因為您試圖重新初始化現有數據庫。 您需要包括的是.withOption("destroy", true)以:

$scope.dtOptions = DTOptionsBuilder.newOptions()

這樣可以解決問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM