I need assistance with initializing a datatable for a table that has a unique id. Can you provide guidance on the syntax to achieve this?
Here is an example of my table structure:
<table id="myDataTable">
<thead>
<tr>
<th>Employee Id</th>
<th>Employee Name</th>
<th>Designation</th>
</tr>
</thead>
<tbody>
<tr>
<td>123451</td>
<td>Employee 1</td>
<td>Senior Developer</td>
</tr>
<tr>
<td>123452</td>
<td>Employee 2</td>
<td>Developer</td>
</tr>
</tbody>
</table>
In my TypeScript file, I attempted the following code:
@ViewChild('myDataTable') myDataTable: ElementRef;
ngOnInit(){
this.myDataTable.nativeElement.dataTable({
pagingType : 'full_numbers'
});
}
Unfortunately, this resulted in an error in the browser console:
"Cannot read property 'nativeElement' of undefined"
Is there an alternative approach to achieving this without using jQuery ($)?