This repository was archived by the owner on Feb 2, 2025. It is now read-only.
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
8000
Uh oh!
There was an error while loading. Please reload this page.
-
I am using Angular 13 and these are the packages
@types/datatables](https://datatables.net/forums/profile/types%2Fdatatables).net@1.10.21
+-- @types/jasmine@3.10.18
+-- @types/jquery@3.5.29
+-- @types/node@12.20.55
+-- angular-datatables@13.1.0
+-- datatables.net-dt@1.13.11
+-- datatables.net@1.13.11
In the component ts
@ViewChild(DataTableDirective](https://datatables.net/forums/profile/ViewChild%28DataTableDirective), { static: false }) dtElement!: DataTableDirective;
dtOptions: DataTables.Settings = {};
dtTrigger: Subject = new Subject();
this.dtOptions = {
ajax: (_dParams, callback) => {
callback({
data: this.subCategories
});
},
columns: [
{
title: 'Id',
data: 'subCategoryId'
},
{
title: 'Sub-Category name',
data: 'subCategoryName'
}
]
};
reloadTable() {
this.dtElement.dtInstance.then(dtInstance => {
Plain text
1
2
3
dtInstance.destroy();
this.dtTrigger.next(null);
})
}
ngAfterViewInit() {
this.dtTrigger.next(null);
}
ngOnDestroy() {
this.dtTrigger.unsubscribe();
}
There are no console errors but the datatables is just not there i cannot see it in the dev tools but if i setTimeout on reloadTable and call it in ngAfterViewInit the table will be there but i will get Cannot read properties of undefined (reading 'dtInstance') but the table is shown and works as it should but the only thing that is not correct is that console error. this.subCategories comes from the service but if i make the call inside the ajax block it doesnt make any difference.
Beta Was this translation helpful? Give feedback.
All reactions