I get the result of my rest api in angular in below format :
[
{"city":"Texas", "Name":"John", "Company": "Nike", "ID": 1234},
{"city":"New york", "Name":"Palmi", "Company": "Docker", "ID": 5678},
{"city":"Alabam", "Name":"Dave", "Company": "Amazon", "ID": 0142},
{"city":"Alabam", "Name":"Dave", "Company": "Amazon", "ID": 0142}
]
And i have a material table to display this table
<mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="Id">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Id</th>
<td mat-cell *matCellDef="let element"> {{element.Id}} </td>
</ng-container>
<ng-container matColumnDef="city">
<th mat-header-cell *matHeaderCellDef mat-sort-header>city</th>
<td mat-cell *matCellDef="let element"> {{element.city}} </td>
</ng-container>
<ng-container matColumnDef="Name">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Name</th>
<td mat-cell *matCellDef="let element"> {{element.Name}} </td>
</ng-container>
<ng-container matColumnDef="Company">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Company</th>
<td mat-cell *matCellDef="let element"> {{element.Company}} </td>
</ng-container>
</mat-table>
<mat-paginator [pageSizeOptions]="[3, 10, 15]" aria-label="List of employees"></mat-paginator>
This material table shows list of employees who must be exported to my pdf
public employeeList(){
const doc = new jsPDF();
autoTable(doc, {
body: [
[
{
content: 'List of employees',
styles: {
halign:'left',
fontSize: 14
}
}
]
],
theme: 'plain'
});
autoTable(doc, {
head: [['id','City','Name','Company']],
body: [
['valFirstId', 'valFirstCity', 'valFirstName', 'valFirstCompany'],
['valSecondId', 'valSecondCity', 'valSecondName', 'valSecondCompany'],
['valThirdId', 'valThirdCity', 'valThirdName', 'valThirdCompany']
],
theme: 'striped',
headStyles:{
fillColor: '#343a40',
}
});
return doc.save("employees");
}
How can I build my body with the result of my API rest in the format above with to add it to my body to replace this :
body: [
['valFirstId', 'valFirstCity', 'valFirstName', 'valFirstCompany'],
['valSecondId', 'valSecondCity', 'valSecondName', 'valSecondCompany'],
['valThirdId', 'valThirdCity', 'valThirdName', 'valThirdCompany']
]