I am using angularjs Datatables and keep running into an error.
DataTables Warning: table id=DataTables_Table_0 - Cannot reinitialise Datatable.
I have tried to use bDestroy and bRetrieve to fix this error. With these options error is not displaying but a blank page is coming now. I am using angularjs http request to display content in table and calling this http request method after every 15 seconds. Please let me know how to get rid of this error.
This is my code:
app.controller('TaxiCompanyController', ['$scope', '$http', '$window', 'ngDialog', 'DTOptionsBuilder', 'DTColumnDefBuilder','$interval','$location', function ($scope, $http, $window, ngDialog, DTOptionsBuilder, DTColumnDefBuilder,$interval,$location) {
var vm = this;
vm.dtOptions = DTOptionsBuilder.newOptions()
.withPaginationType('full_numbers')
.withDisplayLength(12)
.withOption('order', [[1, 'asc']])
.withOption('bDestroy', true)
.withOption('stateSave', true);
vm.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef(0).notSortable(),
{"orderable": false, "targets": 0}
];
$scope.getData = function (status) { // This would fetch the data on page change.
var qStr;
qStr = '?pagecount=1&pagesize=25';
var st = $location.search().st;
if(typeof(st) != 'undefined' && st != '') {
qStr += '&status=' + st;
$scope.company_status = st;
}
if (status != '') {
qStr += '&status=' + status;
}
$http({
method: 'GET',
url: '/users/1/' + qStr
}).then(function successCallback(response) {
var res = angular.fromJson(response);
if (res.data != '') {
if (res.data.success == true) {
if (res.data.result != '') {
vm.companies = res.data.result.users;
}
} else {
if (res.data.error_key == 'token_invalid') {
window.location.href = '/';
} else {
$scope.errorMsg = displayErrors(res.data.error_key, res.data.error);
}
}
}
$scope.spinner = {
hide: true,
show: false
}
}, function errorCallback(response) {
$scope.spinner = {
hide: true,
show: false
}
$scope.errorMsg = "<div class='alert alert-danger' role='alert'><i class='fa fa-exclamation-triangle' aria-hidden='true'></i> There is something wrong!</div>";
});
};
$scope.getData('');
$interval(function () {
$scope.getData('');
}, 10000);
}]);