I am working on the angular based project. I am using datatables to display data. When I try to do some modifications on the table, I get the following error.
DataT
I have tried this in angular 7 and it worked.. runtime datatable changed
.Ts file
import { Component, AfterViewInit, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { DataTableDirective } from 'angular-datatables';
@Component({
selector: 'app-selector',
templateUrl: 'app-selector.component.html'
})
export class CustomRangeSearchComponent implements AfterViewInit, OnDestroy, OnInit {
@ViewChild(DataTableDirective, {static: false})
datatableElement: DataTableDirective;
dtOptions: DataTables.Settings = {};
tableData = [];
ngOnInit(): void {
this.dtOptions = {
destroy: true,
ordering: true,
pagelength: 10,
pagingType: "full_numbers",
columnDefs: [{
targets: 0,
checkboxes:{
selectRow: true,
selected: true
}]
};
}
ngOnDestroy(): void {
$.fn['dataTable'].ext.search.pop();
}
ngAfterViewInit(): void {
this.dtTrigger.next();
}
getdata(){
//... get your response
this.tableData = response; //this should be in array
setTimeout(() => {
this.datatableElement.dtInstance.then((dtInstance: DataTables.Api) => {
dtInstance.draw();
});
});
}
}
.HTML file