我正在以角度4实现jquery数据表。我通过搜索日期范围来填充表格。所以我需要在每次搜索之前销毁数据表。
但是这个功能" rerender()"抛出此错误:ERROR TypeError: 无法阅读财产'然后'未定义的
rerender():void {
this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
// Destroy the table first
dtInstance.destroy();
// Call the dtTrigger to rerender again
this.dtTrigger.next();
})
}
完整代码:
export class vendorTransactionComponent implements OnInit {
@ViewChild(DataTableDirective)
dtElement: DataTableDirective;
dtOptions: any = {};
dtTrigger: Subject<any> = new Subject();
Vendors: any[];
data: any[];
fromDate: Date = new Date();
toDate: Date = new Date();
VendorId: number = 1;
ClientId: number;
items = new Array;
itemCount = 0;
searchkey: any;
IsTableVisible: boolean = false;
IsLoadingDivVisible: boolean = false;
itemLimit = 10;
vendortransactionList: any[] = [];
constructor(private vendortrans_serv: vendorTransactionServices) {
this.ClientId = ConstantData.ClientID;
this.vendortrans_serv.GetAllVendor().subscribe(data => {
this.Vendors = data;
});
}
ngOnInit(): void {
this.dtOptions = {
pagingType: 'full_numbers',
//pageLength: 2,
responsive: true,
};
}
rerender():void {
this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
// Destroy the table first
dtInstance.destroy();
// Call the dtTrigger to rerender again
this.dtTrigger.next();
})
}
GetVendortransaction() {
this.vendortransactionList = [];
this.IsTableVisible = false;
this.IsLoadingDivVisible = true;
this.rerender();
this.vendortrans_serv.GetVendortransactions(this.fromDate.toDateString(), this.toDate.toDateString(), this.ClientId, this.VendorId)
.subscribe(data => {
if (data.length > 0) {
this.vendortransactionList = data;
this.IsTableVisible = true;
// this.dtTrigger.next();
}
this.IsLoadingDivVisible = false;
});
}
}
我正在关注以下文章 http://l-lin.github.io/angular-datatables/#/advanced/rerender