how can i populate the Datatable with the json data i got from backend? in console.log data appears correctly
i got the data but i cant send them in datatable i used many ways but all failed i instructions from http://l-lin.github.io/angular-datatables/#/basic/server-side-angular-way were not very helpful
----------in html file-------
<table datatable [dtOptions]="dtOptions" class="row-border hover"><!--id="userTable"-->
<thead>
<tr>
<th>ID</th>
<th>User Name</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Phone</th>
<th>Enabled</th>
<th>isDoctor</th>
<th>Account</th>
<th>DeleteAcc</th>
</tr>
</thead>
<tbody *ngIf="patientUser?.length != 0">
<tr *ngFor="let patient of patientUser">
<td>{{patient.patientID}}</td>
<td>{{patient.username}}</td>
<td>{{patient.firstName}}</td>
<td>{{patient.lastName}}</td>
<td>{{patient.email}}</td>
<td>{{patient.phone}}</td>
<td>{{patient.enabled}}</td>
<td [hidden]="patient.doctorIs"><a (click)="enableDoctor(patient.username)" style="cursor: pointer;">Enable</a></td>
<td [hidden]="!patient.doctorIs"><a (click)="disableDoctor(patient.username)" style="cursor: pointer;">Disable</a></td>
<td [hidden]="patient.enabled"><a (click)="enableUser(patient.username)" style="cursor: pointer;">Enable</a></td>
<td [hidden]="!patient.enabled"><a (click)="disableUser(patient.username)" style="cursor: pointer;">Disable</a></td>
<td ><a (click)="deleteUser(patient.patientID)" style="cursor: pointer;">Delete</a></td>
</tr>
<tbody *ngIf="patientUser?.length == 0">
<tr>
<td colspan="3" class="no-data-available">No data!</td>
</tr>
</tbody>
-----in component file below------
dtOptions: any = {};
const that = this;
let url = "http://localhost:8015/api/patient/all";
this.dtOptions = {
ajax: () => {
that.http
.get<UserAccountComponent>(
url,
{withCredentials: true}
).subscribe(resp => {
this.test=JSON.stringify(resp);
that.patientUser = JSON.parse(JSON.stringify(resp));
});
},
// Declare the use of the extension in the dom parameter
columns: [{
title: 'ID',
data: 'patientID'
}, {
title: 'First name',
data: 'firstName'
}, {
title: 'Last name',
data: 'lastName'
}],
dom: 'Bfrtip',
// Configure the buttons
buttons: [
'columnsToggle',
'colvis',
'copy',
'print',
'excel'
]
};